<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 721</TITLE>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<STYLE TYPE="text/css">
  INS { text-decoration:none; font-weight:bold; background-color:#A0FFA0 }
  .INS { text-decoration:none; background-color:#D0FFD0 }
  DEL { text-decoration:line-through; background-color:#FFA0A0 }
  .DEL { text-decoration:line-through; background-color: #FFD0D0 }
  @media (prefers-color-scheme: dark) {
    HTML { background-color:#202020; color:#f0f0f0; }
    A { color:#5bc0ff; }
    A:visited { color:#c6a8ff; }
    A:hover, a:focus { color:#afd7ff; }
    INS { background-color:#033a16; color:#aff5b4; }
    .INS { background-color: #033a16; }
    DEL { background-color:#67060c; color:#ffdcd7; }
    .DEL { background-color:#67060c; }
  }
  SPAN.cmnt { font-family:Times; font-style:italic }
</STYLE>
</HEAD>
<BODY>
<P><EM>This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21
  Core Issues List revision 118b.
  See http://www.open-std.org/jtc1/sc22/wg21/ for the official
  list.</EM></P>
<P>2025-09-28</P>
<HR>
<A NAME="721"></A><H4>721.
  
Where must a variable be initialized to be used in a constant expression?
</H4>
<B>Section: </B>7.7&#160; [<A href="https://wg21.link/expr.const">expr.const</A>]
 &#160;&#160;&#160;

 <B>Status: </B>CD2
 &#160;&#160;&#160;

 <B>Submitter: </B>James Kanze
 &#160;&#160;&#160;

 <B>Date: </B>22 September, 2008<BR>


<P>[Voted into WP at October, 2009 meeting.]</P>



<P>7.7 [<A href="https://wg21.link/expr.const#2">expr.const</A>] paragraph 2 allows an
lvalue-to-rvalue conversion in a constant expression if it is
applied to &#8220;an lvalue of effective integral type that
refers to a non-volatile const variable or static data member
initialized with constant expressions.&#8221;  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 <I>member-specification</I> of its
class.</P>

<P><B>Proposed resolution (March, 2009):</B></P>

<P>Change 7.7 [<A href="https://wg21.link/expr.const#2">expr.const</A>] paragraph 2, bullet 4,
sub-bullet 1 as follows:</P>

<UL><LI><P>an lvalue of effective integral type that refers to a
non-volatile const variable <INS>with a preceding
initialization</INS> or <INS>to a non-volatile const</INS> static data
member <INS>with an initialization in the class definition
(11.4.9.3 [<A href="https://wg21.link/class.static.data">class.static.data</A>]), in either case</INS> initialized with
constant expressions, or</P></LI></UL>

<P><B>Additional note, June, 2009:</B></P>

<P>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</P>

<PRE>
    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];
</PRE>

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

<P><B>Proposed resolution (July, 2009):</B></P>

<P>Change 7.7 [<A href="https://wg21.link/expr.const#2">expr.const</A>] paragraph 2, bullet 4,
sub-bullet 1 as follows:</P>

<UL><LI>an lvalue of effective integral type that refers to a
non-volatile const variable <DEL>or static data member</DEL> <INS>with
a preceding initialization,</INS> initialized with <INS>a</INS>
constant expression<DEL>s</DEL>, or</LI></UL>

<BR><BR>
</BODY>
</HTML>
