Created on 2023-09-12.00:00:00 last changed 1 month ago
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, ...
[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.
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2025-09-12 22:42:26 | admin | set | status: open -> cd7 |
| 2025-09-12 22:42:26 | admin | set | status: drwp -> open |
| 2024-04-05 21:43:46 | admin | set | status: dr -> drwp |
| 2023-12-19 10:15:28 | admin | set | status: ready -> dr |
| 2023-12-02 15:54:05 | admin | set | status: tentatively ready -> ready |
| 2023-10-06 22:55:13 | admin | set | status: open -> tentatively ready |
| 2023-09-17 14:47:04 | admin | set | messages: + msg7441 |
| 2023-09-12 00:00:00 | admin | create | |