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

2024-12-19


2909. Subtle difference between constant-initialized and constexpr

Section: 7.7  [expr.const]     Status: DR     Submitter: CWG     Date: 2024-06-24

[Accepted as a DR at the November, 2024 meeting.]

Subclause 7.7 [expr.const] paragraph 2 defines "constant-initialized" using the following rule:

A variable or temporary object o is constant-initialized if

However, the rules for constexpr are slightly different, per 9.2.6 [dcl.constexpr] paragraph 6:

A constexpr specifier used in an object declaration declares the object as const. Such an object shall have literal type and shall be initialized. ...

The difference manifests for an example such as:

  struct S {};
  int main() {
    constexpr S s;       // OK
    constexpr S s2 = s;  // error: s is not constant-initialized
  }

Is the difference intentional?

Proposed resolution (approved by CWG 2024-10-25):

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

A variable or temporary object o is constant-initialized if