This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 115e. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.
2024-11-11
[Accepted as a DR at the November, 2023 meeting.]
The message of a static_assert declaration is a conditional-expression and thus is not manifestly constant evaluated. Consider this example:
struct X { std::string s; const char *p; }; consteval X f() { return {.s = "some long string that requires a heap allocation", .p = "hello"}; } static_assert(cond, f().p);
The example is ill-formed, because the immediate invocation f() lets a pointer to the heap escape.
Proposed resolution (approved by CWG 2023-10-06):
Change in 7.7 [expr.const] paragraph 19 as follows:
[Note 11: Except for a static_assert-message, aAmanifestly constant-evaluated expression is evaluated even in an unevaluated operand (7.2.3 [expr.context]). —end note]
Change the grammar in 9.1 [dcl.pre] as follows:
static_assert-message: unevaluated-stringconditional-expressionconstant-expression
Change in 9.1 [dcl.pre] bullet 11.2 as follows:
- ...
- if the static_assert-message is a
conditional-expressionconstant-expression M, ...