Title
Manifestly constant evaluation of the static_assert message
Status
drwp
Section
7.7 [expr.const]
Submitter
Jason Merrill

Created on 2023-09-12.00:00:00 last changed 3 weeks ago

Messages

Date: 2023-10-06.22:55:13

Proposed resolution (approved by CWG 2023-10-06):

  1. Change in 7.7 [expr.const] paragraph 19 as follows:

    [Note 11: Except for a static_assert-message, a A manifestly constant-evaluated expression is evaluated even in an unevaluated operand (7.2.3 [expr.context]). —end note]
  2. Change the grammar in 9.1 [dcl.pre] as follows:

    static_assert-message:
      unevaluated-string
      conditional-expression constant-expression
    
  3. Change in 9.1 [dcl.pre] bullet 11.2 as follows:

    • ...
    • if the static_assert-message is a conditional-expression constant-expression M, ...
Date: 2023-11-15.00:00:00

[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
2024-04-05 21:43:46adminsetstatus: dr -> drwp
2023-12-19 10:15:28adminsetstatus: ready -> dr
2023-12-02 15:54:05adminsetstatus: tentatively ready -> ready
2023-10-06 22:55:13adminsetstatus: open -> tentatively ready
2023-09-17 14:47:04adminsetmessages: + msg7441
2023-09-12 00:00:00admincreate