This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 119d. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2026-03-08


3161. Self-initialization of constexpr-unknown references

Section: 7.7  [expr.const]     Status: open     Submitter: Corentin Jabot     Date: 2025-03-26

(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.

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 ]