Title
Can default initialization be constant initialization?
Status
cd5
Section
6.9.3.2 [basic.start.static]
Submitter
Geoffrey Romer

Created on 2017-11-01.00:00:00 last changed 47 months ago

Messages

Date: 2020-12-15.00:00:00

Proposed resolution, June, 2019:

  1. Change 6.9.3.2 [basic.start.static] paragraph 2 as follows:

  2. Constant initialization is performed if a variable or temporary object with static or thread storage duration is constant-initialized by a constant initializer (7.7 [expr.const]) for the entity. If constant initialization is not performed, a variable with static storage duration (6.7.5.2 [basic.stc.static]) or thread storage duration (6.7.5.3 [basic.stc.thread]) is zero-initialized (9.4 [dcl.init]). Together, zero-initialization and constant initialization...
  3. Change 7.7 [expr.const] paragraph 2 as follows:

  4. A constant initializer for a variable or temporary object o is an initializer for which interpreting its full-expression as a constant-expression results in a constant expression constant-initialized if

    • either it has an initializer or its default-initialization results in some initialization being performed, and

    • its initialization full-expression is a constant expression when interpreted as a constant-expression, except that if o is an object, such an initializer the initialization full-expression may also invoke constexpr constructors for o and its subobjects even if those objects are of non-literal class types. [Note: Such a class may have a non-trivial destructor. Within this evaluation, std::is_constant_evaluated() (21.3.11 [meta.const.eval]) returns true. —end note]

  5. Change 7.7 [expr.const] paragraph 3 as follows:

  6. A variable is usable in constant expressions after its initializing declaration is encountered if it is a constexpr variable, or it is a constant-initialized variable of reference type or of const-qualified integral or enumeration type, and its initializer is a constant initializer.
  7. Change 9.2.6 [dcl.constexpr] paragraph 5 as follows:

  8. For a constexpr function or constexpr constructor that is neither defaulted nor a template, if no argument values exist such that an invocation of the function or constructor could be an evaluated subexpression of a core constant expression (7.7 [expr.const]), or, for a constructor, a constant initializer for an evaluated subexpression of the initialization full-expression of some constant-initialized object (6.9.3.2 [basic.start.static]), the program is ill-formed, no diagnostic required. [Example:...
Date: 2018-10-15.00:00:00

Notes from the October, 2018 teleconference:

CWG agreed that the example should be well-formed.

Date: 2019-07-15.00:00:00

[Accepted as a DR at the July, 2019 meeting.]

According to 6.9.3.2 [basic.start.static] paragraph 2,

Constant initialization is performed if a variable or temporary object with static or thread storage duration is initialized by a constant initializer for the entity. If constant initialization is not performed, a variable with static storage duration (6.7.5.2 [basic.stc.static]) or thread storage duration (6.7.5.3 [basic.stc.thread]) is zero-initialized (9.4 [dcl.init]). Together, zero-initialization and constant initialization are called static initialization; all other initialization is dynamic initialization.

This appears to require an explicit initializer for constant initialization and would preclude examples like:

  struct S {
    int i = 1;
  };
  static constexpr S s;

where there is no initializer.

History
Date User Action Args
2020-12-15 00:00:00adminsetmessages: + msg6369
2020-12-15 00:00:00adminsetmessages: + msg6368
2017-11-01 00:00:00admincreate