<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 177</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="177"></A><H4>177.
  
Lvalues vs rvalues in copy-initialization
</H4>
<B>Section: </B>9.5&#160; [<A href="https://wg21.link/dcl.init">dcl.init</A>]
 &#160;&#160;&#160;

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

 <B>Submitter: </B>Steve Adamczyk
 &#160;&#160;&#160;

 <B>Date: </B>25 October 1999<BR>



<P>[Moved to DR at 4/02 meeting.]</P>

<P>Is the temporary created during copy-initialization of a class object
treated as an lvalue or an rvalue?  That is, is the following example
well-formed or not?</P>

<PRE>
    struct B { };
    struct A {
        A(A&amp;);    // not const
        A(const B&amp;);
    };
    B b;
    A a = b;
</PRE>

<P>According to 9.5 [<A href="https://wg21.link/dcl.init">dcl.init</A>]
paragraph
14, the initialization of <TT>a</TT> is performed in two steps.
First, a temporary of type <TT>A</TT> is created using <TT>A::A(const
B&amp;)</TT>.  Second, the resulting temporary is used to
direct-initialize <TT>a</TT> using <TT>A::A(A&amp;)</TT>.</P>

<P>The second step requires binding a reference to non-const to the
temporary resulting from the first step.  However,
9.5.4 [<A href="https://wg21.link/dcl.init.ref#5">dcl.init.ref</A>] paragraph 5
requires
that such a reference be bound only to lvalues.</P>

<P>It is not clear from 7.2.1 [<A href="https://wg21.link/basic.lval">basic.lval</A>]

whether the temporary created in the process of copy-initialization
should be treated as an lvalue or an rvalue.  If it is an lvalue, the
example is well-formed, otherwise it is ill-formed.</P>

<P><B>Proposed resolution (04/01):</B></P>

<OL>
<LI>
<P>In 9.5 [<A href="https://wg21.link/dcl.init#14">dcl.init</A>] paragraph 14, insert
the following after "the call initializes a temporary of
the destination type":</P>

<BLOCKQUOTE>

The temporary is an rvalue.

</BLOCKQUOTE>
</LI>

<LI>
<P>In 14.2 [<A href="https://wg21.link/except.throw#3">except.throw</A>] paragraph 3, replace</P>

<BLOCKQUOTE>

The temporary is used to initialize the variable...

</BLOCKQUOTE>

<P>with</P>

<BLOCKQUOTE>

The temporary is an lvalue and is used to initialize
the variable...

</BLOCKQUOTE>

</LI>

</OL>

<P>(See also <A HREF="84.html">issue 84</A>.)</P>
<BR><BR>
</BODY>
</HTML>
