Skip to content

Commit

Permalink
P2264R7 Make assert() macro user friendly for C and C++
Browse files Browse the repository at this point in the history
  • Loading branch information
burblebee committed Nov 17, 2023
1 parent 5c0103c commit eee9363
Showing 1 changed file with 43 additions and 2 deletions.
45 changes: 43 additions & 2 deletions source/diagnostics.tex
Original file line number Diff line number Diff line change
Expand Up @@ -451,13 +451,13 @@
\pnum
The header \libheaderdef{cassert}
provides a macro for documenting \Cpp{} program assertions and a mechanism
for disabling the assertion checks.
for disabling the assertion checks through defining the macro \tcode{NDEBUG}.

\rSec2[cassert.syn]{Header \tcode{<cassert>} synopsis}

\indexlibraryglobal{assert}%
\begin{codeblock}
#define assert(E) @\seebelow@
#define assert(...) @\seebelow@
\end{codeblock}

\pnum
Expand All @@ -471,6 +471,47 @@

\rSec2[assertions.assert]{The \tcode{assert} macro}

\pnum
If \tcode{NDEBUG} is defined as a macro name
at the point in the source file where \tcode{<cassert>} is included,
the \tcode{assert} macro is defined as
\begin{codeblock}
#define assert(...) ((void)0)
\end{codeblock}

\pnum
Otherwise, the \tcode{assert} macro puts a diagnostic test into programs;
it expands to an expression of type \keyword{void} which
has the following effects:

\begin{itemize}
\item
\tcode{__VA_ARGS__} is evaluated and contextually converted to \tcode{bool}.
\item
If the evaluation yields \tcode{true} there are no further effects.
\item
Otherwise, the \tcode{assert} macro's expression
creates a diagnostic on the standard error stream in an
\impldef{format of diagnostic created by \tcode{assert} macro's expression}
format and calls \tcode{abort()}.
The diagnostic contains \tcode{\#__VA_ARGS__} and
information on
the name of the source file,
the source line number, and
the name of the enclosing function
(such as provided by \tcode{source_location::current()}).
\end{itemize}

\pnum
If \tcode{__VA_ARGS__} does not expand to
an \grammarterm{assignment-expression},
the program is ill-formed.

\pnum
The macro \tcode{assert} is redefined according to
the current state of \tcode{NDEBUG} each time that
\tcode{<cassert>} is included.

\pnum
An expression \tcode{assert(E)}
is a constant subexpression\iref{defns.const.subexpr}, if
Expand Down

0 comments on commit eee9363

Please sign in to comment.