Title
Constant expressions, aggregate initialization, and modifications
Status
nad
Section
7.7 [expr.const]
Submitter
Mike Miller

Created on 2017-10-31.00:00:00 last changed 46 months ago

Messages

Date: 2021-02-17.00:00:00

Rationale, February, 2021:

The resolution of 2256 makes clear that the lifetime of x has not begun because its initialization is not yet complete, so the assignment is undefined behavior and thus ill-formed in a constant expression.

Date: 2018-10-15.00:00:00

Notes from the October, 2018 teleconference:

This kind of example was previously ill-formed but it was inadvertently allowed by the change to the “non-vacuous initialization” rule. That rule should be restricted to class and array types, making this example again ill-formed.

Date: 2017-10-31.00:00:00

There is implementation variance in the treatment of the following example:

  constexpr int f(int x) { return x; }
  int main() {
    struct {
      int x = f(x = 37);
    } constexpr a = { };
  }

Is the assignment to x considered to satisfy the requirememts of 7.7 [expr.const] bullet 2.17,

modification of an object (7.6.19 [expr.ass], 7.6.1.6 [expr.post.incr], 7.6.2.3 [expr.pre.incr]) unless it is applied to a non-volatile lvalue of literal type that refers to a non-volatile object whose lifetime began within the evaluation of e;

assuming that e is the full-expression encompassing the initialization of a?

History
Date User Action Args
2021-02-17 00:00:00adminsetmessages: + msg6509
2021-02-17 00:00:00adminsetstatus: drafting -> nad
2020-12-15 00:00:00adminsetmessages: + msg6237
2020-12-15 00:00:00adminsetstatus: open -> drafting
2017-10-31 00:00:00admincreate