This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 110c. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2023-02-07


721. Where must a variable be initialized to be used in a constant expression?

Section: 7.7  [expr.const]     Status: CD2     Submitter: James Kanze     Date: 22 September, 2008

[Voted into WP at October, 2009 meeting.]

7.7 [expr.const] paragraph 2 allows an lvalue-to-rvalue conversion in a constant expression if it is applied to “an lvalue of effective integral type that refers to a non-volatile const variable or static data member initialized with constant expressions.” However, this does not require, as it presumably should, that the initialization occur in the same translation unit and precede the constant expression, nor that the static data member be initialized within the member-specification of its class.

Proposed resolution (March, 2009):

Change 7.7 [expr.const] paragraph 2, bullet 4, sub-bullet 1 as follows:

Additional note, June, 2009:

It has been suggested that the requirement that a static data member be initialized in the class definition is not actually needed but that static data members should be treated like other variable declarations -- a preceding definition with initialization should be sufficient. That is, given

    extern const int i;
    const int i = 5;
    struct S {
      static const int j;
    };
    const int S::j = 5;
    int a1[i];
    int a2[S::j];

there doesn't appear to be a good rationale for making a1 well-formed and a2 ill-formed. Some major implementations accept the declaration of a2 without error.

Proposed resolution (July, 2009):

Change 7.7 [expr.const] paragraph 2, bullet 4, sub-bullet 1 as follows: