Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 64ad91d

Browse filesBrowse files
authored
Merge 2023-11 LWG Motion 18
P2264R7 Make assert() macro user friendly for C and C++
2 parents c28d8ac + fdbdb75 commit 64ad91d
Copy full SHA for 64ad91d

File tree

Expand file treeCollapse file tree

1 file changed

+41
-9
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+41
-9
lines changed

‎source/diagnostics.tex

Copy file name to clipboardExpand all lines: source/diagnostics.tex
+41-9Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -451,25 +451,57 @@
451451
\pnum
452452
The header \libheaderdef{cassert}
453453
provides a macro for documenting \Cpp{} program assertions and a mechanism
454-
for disabling the assertion checks.
454+
for disabling the assertion checks through defining the macro \tcode{NDEBUG}.
455455

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

458458
\indexlibraryglobal{assert}%
459459
\begin{codeblock}
460-
#define assert(E) @\seebelow@
460+
#define assert(...) @\seebelow@
461461
\end{codeblock}
462462

463+
\rSec2[assertions.assert]{The \tcode{assert} macro}
464+
463465
\pnum
464-
\indextext{static_assert@\tcode{static_assert}!not macro}%
465-
The contents are the same as the C standard library header
466-
\libheader{assert.h},
467-
except that a macro named \keyword{static_assert}
468-
is not defined.
466+
If \tcode{NDEBUG} is defined as a macro name
467+
at the point in the source file where \tcode{<cassert>} is included,
468+
the \tcode{assert} macro is defined as
469+
\begin{codeblock}
470+
#define assert(...) ((void)0)
471+
\end{codeblock}
469472

470-
\xrefc{7.2}
473+
\pnum
474+
Otherwise, the \tcode{assert} macro puts a diagnostic test into programs;
475+
it expands to an expression of type \keyword{void} which
476+
has the following effects:
471477

472-
\rSec2[assertions.assert]{The \tcode{assert} macro}
478+
\begin{itemize}
479+
\item
480+
\mname{VA_ARGS} is evaluated and contextually converted to \tcode{bool}.
481+
\item
482+
If the evaluation yields \tcode{true} there are no further effects.
483+
\item
484+
Otherwise, the \tcode{assert} macro's expression
485+
creates a diagnostic on the standard error stream in an
486+
\impldef{format of diagnostic created by \tcode{assert} macro's expression}
487+
format and calls \tcode{abort()}.
488+
The diagnostic contains \tcode{\#}\mname{VA_ARGS} and
489+
information on
490+
the name of the source file,
491+
the source line number, and
492+
the name of the enclosing function
493+
(such as provided by \tcode{source_location::current()}).
494+
\end{itemize}
495+
496+
\pnum
497+
If \mname{VA_ARGS} does not expand to
498+
an \grammarterm{assignment-expression},
499+
the program is ill-formed.
500+
501+
\pnum
502+
The macro \tcode{assert} is redefined according to
503+
the current state of \tcode{NDEBUG} each time that
504+
\tcode{<cassert>} is included.
473505

474506
\pnum
475507
An expression \tcode{assert(E)}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.