Files
cppdraft_translate/cppdraft/assertions.md
2025-10-25 03:02:53 +03:00

3.1 KiB
Raw Permalink Blame History

[assertions]

19 Diagnostics library [diagnostics]

19.3 Assertions [assertions]

19.3.1 General [assertions.general]

1

#

The header provides a macro for documenting C++ program assertions and a mechanism for disabling the assertion checks through defining the macro NDEBUG.

19.3.2 Header synopsis [cassert.syn]

#define assert(...) see below

19.3.3 The assert macro [assertions.assert]

1

#

If NDEBUG is defined as a macro name at the point in the source file where is included, the assert macro is defined as#define assert(...) ((void)0)

2

#

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

  • (2.1)

    VA_ARGS is evaluated and contextually converted to bool.

  • (2.2)

    If the evaluation yields true there are no further effects.

  • (2.3)

    Otherwise, the assert macro's expression creates a diagnostic on the standard error stream (ISO/IEC 9899:2024, 7.23.3) in animplementation-defined format and calls abort(). The diagnostic contains #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 source_location::current()).

3

#

If VA_ARGS does not expand to an assignment-expression, the program is ill-formed.

4

#

The macro assert is redefined according to the current state of NDEBUG each time that is included.

5

#

An expression assert(E) is a constant subexpression, if

NDEBUG is defined at the point where assert is last defined or redefined, or

E contextually converted to bool is a constant subexpression that evaluates to the value true.