<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 615</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="615"></A><H4>615.
  
Incorrect description of variables that can be initialized
</H4>
<B>Section: </B>9.5&#160; [<A href="https://wg21.link/dcl.init">dcl.init</A>]
 &#160;&#160;&#160;

 <B>Status: </B>C++11
 &#160;&#160;&#160;

 <B>Submitter: </B>comp.std.c++
 &#160;&#160;&#160;

 <B>Date: </B>30 January 2007<BR>


<P>[Voted into WP at August, 2010 meeting.]</P>

<P>9.5 [<A href="https://wg21.link/dcl.init#2">dcl.init</A>] paragraph 2 reads,</P>

<BLOCKQUOTE>

Automatic, register, static, and external variables of namespace scope
can be initialized by arbitrary expressions involving literals and
previously declared variables and functions.

</BLOCKQUOTE>

<P>Both &#8220;automatic&#8221; and &#8220;static&#8221; are used to
describe <I>storage durations</I>, &#8220;register&#8221; is
a <I>storage class specifier</I> which indicates the object has
automatic storage duration, &#8220;external&#8221;
describes <I>linkage</I>, and &#8220;namespace scope&#8221; is a kind
of <I>scope</I>. Automatic, register, static and external, together
with namespace scope, are used to restrict the
&#8220;variables.&#8221;</P>

<P>Register objects are only a sub-set of automatic objects and thus
the word &#8220;register&#8221; is redundant and should be elided. If
register objects are to be emphasized, they should be mentioned like
&#8220;Automatic (including register)...&#8221;</P>

<P>Variables having namespace scope can never be automatic; they can
only be static, with either external or internal linkage. Therefore,
there are in fact no &#8220;automatic variables of namespace
scope,&#8221; and the &#8220;static&#8221; in &#8220;static variables
of namespace scope&#8221; is useless.</P>

<P>In fact, automatic and static variables already compose all
variables with either external linkage or not, and thus the
&#8220;external&#8221; becomes redundant, too, and the quoted sentence
seems to mean that all variables of namespace scope can be initialized
by arbitrary expressions. But this is not true because not all
internal variables of namespace scope can. Therefore, the restrictive
&#8220;external&#8221; is really necessary, not redundant.</P>

<P>As a result, the erroneous restrictive &#8220;automatic, register,
static&#8221; should be removed and the quoted sentence may be changed
to:</P>

<BLOCKQUOTE>

External variables of namespace scope can be initialized by arbitrary
expressions involving literals and previously declared variables and
functions.

</BLOCKQUOTE>

<P><B>Notes from the April, 2007 meeting:</B></P>

<P>This sentence is poorly worded, but the analysis given in
the issue description is incorrect.  The intent is simply that
the storage class of a variable places no restrictions on the
kind of expression that can be used to initialize it (in contrast
to C, where variables of static storage duration can only be
initialized by constant expressions).</P>

<P><B>Proposed resolution (June, 2008):</B></P>

<P>Change 9.5 [<A href="https://wg21.link/dcl.init#2">dcl.init</A>] paragraph 2 as follows:</P>

<BLOCKQUOTE>

<DEL>Automatic, register, static, and external variables of namespace scope</DEL>
<INS>Variables of automatic, thread, and static storage duration</INS> can
be initialized by arbitrary expressions involving literals and
previously declared variables and functions...

</BLOCKQUOTE>

<P><B>Notes from the September, 2008 meeting:</B></P>

<P>The existing wording is intended to exclude block-scope
<TT>extern</TT> declarations but to allow initializers in all
other forms of variable declarations.  The best way to phrase
that is probably to say that all variable definitions (except for
function parameters, where the initializer syntax is used for
default arguments) can have arbitrary expressions as
initializers, regardless of storage duration.</P>

<P><B>Proposed resolution (February, 2010):</B></P>

<P>Change 9.5 [<A href="https://wg21.link/dcl.init#2">dcl.init</A>] paragraph 2 as follows:</P>

<BLOCKQUOTE>

<DEL>Automatic, register, thread_local, static, and
namespace-scoped external variables can be initialized by</DEL>
<INS>Except for objects declared with the <TT>constexpr</TT>
specifier, for which see 9.2.6 [<A href="https://wg21.link/dcl.constexpr">dcl.constexpr</A>], an
<I>initializer</I> in the definition of a variable can consist
of</INS> arbitrary expressions involving literals and previously
declared variables and functions<INS>, regardless of the
variable's storage duration</INS>. [<I>Example:</I>...

</BLOCKQUOTE>

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