This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 112e. See for the official list.


1921. constexpr constructors and point of initialization of const variables

Section: 7.7  [expr.const]     Status: NAD     Submitter: Ville Voutilainen     Date: 2014-05-02

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.

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.