Uninitialized subobjects as a result of an immediate invocation
7.7 [expr.const]
Aaron Ballman

Created on 2022-03-29.00:00:00 last changed 7 months ago


Date: 2023-01-27.23:50:39

Proposed resolution (approved by CWG 2023-01-27):

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

A constant expression is either a glvalue core constant expression that refers to an entity that is a permitted result of a constant expression (as defined below), or a prvalue core constant expression whose value satisfies the following constraints:
  • if the value is an object of class type, each non-static data member of reference type refers to an entity that is a permitted result of a constant expression,
  • if the value is an object of scalar type, it does not have indeterminate value (6.7.4 [basic.indet]),
  • ...
  • if the value is an object of class or array type, each subobject satisfies these constraints for the value.
Date: 2023-02-15.00:00:00

[Accepted as a DR at the February, 2023 meeting.]


  struct A {
    int n;
    consteval A() {}
  constexpr A a; // implementations reject

Paper P1331R2 (Permitting trivial default initialization in constexpr contexts) dropped the restriction that immediate invocations cannot yield results with some subobjects left uninitialized. It is unclear whether that change was intentional or accidental.

Furthermore, indeterminate values of pointer type are currently not permitted as the result of a constant expression per 7.7 [expr.const] bullet 12.2; indeterminate values of scalar types are permitted only due to the absence of a restriction.

This issue is closely related to issue 2536.


Forwarded to EWG with cplusplus/papers#1380.

EWG 2023-01-19

Uninitialized non-variant direct subobjects should not be allowed to appear in the result of a constant expression. There was no consensus in support of the statements "Union types shall be initialized such that they have an active member in the result of a constant expression" and "EWG confirms that padding bits and data belonging to non-active variant members are permitted to have indeterminate values in the static initialization of objects".

Date User Action Args
2023-07-16 13:00:43adminsetstatus: open -> c++23
2023-07-16 13:00:43adminsetstatus: dr -> open
2023-02-18 18:43:04adminsetstatus: ready -> dr
2023-02-07 14:43:26adminsetstatus: tentatively ready -> ready
2023-01-27 23:50:39adminsetmessages: + msg7152
2023-01-27 23:50:39adminsetstatus: review -> tentatively ready
2023-01-19 21:08:13adminsetstatus: open -> review
2022-03-29 00:00:00admincreate