Title
constexpr constructors and point of initialization of const variables
Status
nad
Section
7.7 [expr.const]
Submitter
Ville Voutilainen

Created on 2014-05-02.00:00:00 last changed 127 months ago

Messages

Date: 2014-06-15.00:00:00

Rationale (June, 2014):

The requirements for a constexpr constructor in 9.2.6 [dcl.constexpr] do not require that an initializer be constant at the point of definition, similar to the provision for mutually-recursive constexpr functions, which require that at least one of the functions will contain a reference to a not-yet-defined constexpr function. Determination of whether an expression is constant or not is made in the context in which the expression appears, by which time the constant value of x in the exampe above is known. CWG feels that the current wording is clear enough that the example is well-formed.

Date: 2022-11-20.07:54:16

In an example like

  extern int const x;

  struct A {
    constexpr A () { }
    int value = x;
  };

  int const x = 123;

  constexpr A a;

it is not clear whether the constructor for A is well-formed (because the initialization for x has not yet been seen) and whether that constant value is used in the initialization of a. There is implementation divergence on these questions.

History
Date User Action Args
2014-07-07 00:00:00adminsetmessages: + msg5112
2014-07-07 00:00:00adminsetstatus: open -> nad
2014-05-02 00:00:00admincreate