<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 684</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="684"></A><H4>684.
  
Constant expressions involving the address of an automatic variable
</H4>
<B>Section: </B>7.7&#160; [<A href="https://wg21.link/expr.const">expr.const</A>]
 &#160;&#160;&#160;

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

 <B>Submitter: </B>Jens Maurer
 &#160;&#160;&#160;

 <B>Date: </B>13 March, 2008<BR>


<P>[Voted into the WP at the September, 2008 meeting (resolution
in paper N2757).]</P>



<P>The expressions that are excluded from being constant expressions
in 7.7 [<A href="https://wg21.link/expr.const#2">expr.const</A>] paragraph 2 does not address an example
like the following:</P>

<PRE>
    void f() {
       int a;
       constexpr int* p = &amp;a;    //<SPAN CLASS="cmnt"> should be ill-formed, currently isn't</SPAN>
    }
</PRE>

<P><U>Suggested resolution:</U></P>

<P>Add the following bullet to the list in 7.7 [<A href="https://wg21.link/expr.const#2">expr.const</A>] paragraph 2:
</P>

<UL><LI><P>an <I>id-expression</I> that refers to a variable with
automatic storage duration unless a permitted lvalue-to-rvalue
conversion is applied (see above)</P></LI></UL>

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

<OL>
<LI><P>Change 6.10.3.2 [<A href="https://wg21.link/basic.start.static#1">basic.start.static</A>] paragraph 1 as
follows:</P></LI>

<BLOCKQUOTE>

Objects with static storage duration (6.8.6.2 [<A href="https://wg21.link/basic.stc.static">basic.stc.static</A>]) or
thread storage duration (3.7.2) shall be zero-initialized
(9.5 [<A href="https://wg21.link/dcl.init">dcl.init</A>]) before any other initialization takes
place. <DEL>A reference with static or thread storage duration and an
object of trivial or literal type with static or thread storage
duration can be initialized with a constant expression (7.7 [<A href="https://wg21.link/expr.const">expr.const</A>]); this is called <I>constant initialization</I>.</DEL>
<INS><I>Constant initialization</I> is performed:

<UL>
<LI><P>if an object of trivial or literal type with static or
thread storage duration is initialized with a constant expression
(7.7 [<A href="https://wg21.link/expr.const">expr.const</A>]), or</P></LI>

<LI><P>if a reference with static or thread storage duration is
initialized with a constant expression that is not an lvalue
designating an object with thread or automatic storage
duration.</P></LI>

</UL>
</INS>
Together, zero-initialization and constant
initialization...

</BLOCKQUOTE>

<LI><P>Add the following in 7.7 [<A href="https://wg21.link/expr.const">expr.const</A>] paragraph
2:</P></LI>

<BLOCKQUOTE>

<UL>
<LI><P>an lvalue-to-rvalue conversion (4.1) unless it is applied
to...</P></LI>

<INS>

<LI><P>an array-to-pointer conversion (7.3.3 [<A href="https://wg21.link/conv.array">conv.array</A>]) that
is applied to an lvalue that designates an object with thread or
automatic storage duration</P></LI>

<LI><P>a unary operator <TT>&amp;</TT> (7.6.2.2 [<A href="https://wg21.link/expr.unary.op">expr.unary.op</A>])
that is applied to an lvalue that designates an object with thread or
automatic storage duration</P></LI>

</INS>

<LI><P>an <I>id-expression</I> that refers to a variable or data
member of reference type;</P></LI>

<LI><P>...</P></LI>

</UL>

</BLOCKQUOTE>

</OL>

<P>(Note: the change to 6.10.3.2 [<A href="https://wg21.link/basic.start.static#1">basic.start.static</A>] paragraph 1
needs to be reconciled with the conflicting change in
<A HREF="688.html">issue 688</A>.)</P>

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