Title
Self-initialization of constexpr-unknown references
Status
open
Section
7.7 [expr.const]
Submitter
Corentin Jabot

Created on 2025-03-26.00:00:00 last changed 1 week ago

Messages

Date: 2026-02-27.07:59:37

Possible resolution:

Change in 7.7 [expr.const] paragraph 16 as follows, also amending the example:

During the evaluation of an expression E as a core constant expression, all id-expressions, splice-expressions, and uses of *this that refer to an object or reference whose lifetime initialization did not begin within the evaluation of E are treated as referring to a specific instance of that object or reference whose lifetime and that of all subobjects (including all union members) includes the entire constant evaluation. ...
  constexpr int f() {
    int& x = x;    // #1
    return 1;
  }
  constexpr int wat = f();  // error: not a constant expression due to #1
-- end example ]
Date: 2025-03-26.00:00:00

(From submission #846.)

Consider:

  constexpr int f() {
    int &x = x;
    return 1;
  }
  constexpr int wat = f(); 

According to 7.7 [expr.const] paragraph 16, this is valid, because x is constexpr-unknown within the initializer of x.

History
Date User Action Args
2026-02-27 07:53:26adminsetmessages: + msg8494
2025-03-26 00:00:00admincreate