|
451 | 451 | \pnum
|
452 | 452 | The header \libheaderdef{cassert}
|
453 | 453 | 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}. |
455 | 455 |
|
456 | 456 | \rSec2[cassert.syn]{Header \tcode{<cassert>} synopsis}
|
457 | 457 |
|
458 | 458 | \indexlibraryglobal{assert}%
|
459 | 459 | \begin{codeblock}
|
460 |
| -#define assert(E) @\seebelow@ |
| 460 | +#define assert(...) @\seebelow@ |
461 | 461 | \end{codeblock}
|
462 | 462 |
|
| 463 | +\rSec2[assertions.assert]{The \tcode{assert} macro} |
| 464 | + |
463 | 465 | \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} |
469 | 472 |
|
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: |
471 | 477 |
|
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. |
473 | 505 |
|
474 | 506 | \pnum
|
475 | 507 | An expression \tcode{assert(E)}
|
|
0 commit comments