<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 2906</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="2906"></A><H4>2906.
  
Lvalue-to-rvalue conversion of class types for conditional operator
</H4>
<B>Section: </B>7.6.16&#160; [<A href="https://wg21.link/expr.cond">expr.cond</A>]
 &#160;&#160;&#160;

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

 <B>Submitter: </B>Jan Schultke
 &#160;&#160;&#160;

 <B>Date: </B>2024-06-08<BR>


<P>[Accepted as a DR at the November, 2024 meeting.]</P>

<P>(From submission
<A HREF="https://github.com/cplusplus/CWG/issues/550">#550</A>.)</P>

<P>There are two known situations where the lvalue-to-rvalue
conversion is applied to class types, which can be non-constexpr even
if the resulting copy constructor invocation would be constexpr
(7.7 [<A href="https://wg21.link/expr.const#5.9">expr.const</A>] bullet 5.9).  The other such situation is
7.6.1.3 [<A href="https://wg21.link/expr.call#11">expr.call</A>] paragraph 11.  Here, the concern is with
7.6.16 [<A href="https://wg21.link/expr.cond#7">expr.cond</A>] paragraph 7, which can be invoked for class
types; for example:</P>

<PRE>
  struct S {};
  S a;
  constexpr S b = a;        //<SPAN CLASS="cmnt"> OK, call to implicitly-declared copy constructor</SPAN>
  constexpr S d = false ? S{} : a; //<SPAN CLASS="cmnt"> error: lvalue-to-rvalue conversion of 'a' is not a constant expression</SPAN>
</PRE>

<P>Major implementations disagree with the ill-formed outcome.</P>

<P><B>Proposed resolution (approved by CWG 2024-06-26):</B></P>

<P>Change in 7.6.16 [<A href="https://wg21.link/expr.cond#7">expr.cond</A>] paragraph 7 as follows:</P>

<BLOCKQUOTE>

<P>
Otherwise, the result is a prvalue. If the second and third operands
do not have the same type, ...
</P>

<P>
<DEL>Lvalue-to-rvalue (7.3.2 [<A href="https://wg21.link/conv.lval">conv.lval</A>]),
array-to-pointer</DEL>
<INS>Array-to-pointer</INS>
(7.3.3 [<A href="https://wg21.link/conv.array">conv.array</A>])<DEL>,</DEL> and function-to-pointer
(7.3.4 [<A href="https://wg21.link/conv.func">conv.func</A>]) standard conversions are performed on the
second and third operands. After those conversions, one of the
following shall hold:
<UL>
<LI>The second and third operands have the same type; the result is of
that type and the result <DEL>object</DEL>
is <DEL>initialized</DEL> <INS>copy-initialized</INS> using the
selected operand.
</LI>
<LI>The second and third operands have arithmetic or enumeration type;
the usual arithmetic conversions (7.4 [<A href="https://wg21.link/expr.arith.conv">expr.arith.conv</A>]) are
performed to bring them to a common type, and the result is of that
type.</LI>
<LI>One or both of the second and third operands have pointer type;
<INS>lvalue-to-rvalue (7.3.2 [<A href="https://wg21.link/conv.lval">conv.lval</A>]),</INS> pointer
<DEL>conversions</DEL> (7.3.12 [<A href="https://wg21.link/conv.ptr">conv.ptr</A>]), function pointer
<DEL>conversions</DEL> (7.3.14 [<A href="https://wg21.link/conv.fctptr">conv.fctptr</A>]), and qualification
conversions (7.3.6 [<A href="https://wg21.link/conv.qual">conv.qual</A>]) are performed to bring them
to their composite pointer type (7.2.2 [<A href="https://wg21.link/expr.type">expr.type</A>]). The
result is of the composite pointer type.</LI>
<LI>One or both of the second and third operands have
pointer-to-member type; <INS>lvalue-to-rvalue
(7.3.2 [<A href="https://wg21.link/conv.lval">conv.lval</A>]),</INS> pointer to
member <DEL>conversions</DEL> (7.3.13 [<A href="https://wg21.link/conv.mem">conv.mem</A>]), function
pointer <DEL>conversions</DEL> (7.3.14 [<A href="https://wg21.link/conv.fctptr">conv.fctptr</A>]), and
qualification conversions (7.3.6 [<A href="https://wg21.link/conv.qual">conv.qual</A>]) are performed
to bring them to their composite pointer type
(7.2.2 [<A href="https://wg21.link/expr.type">expr.type</A>]). The result is of the composite pointer
type.
</LI>
<LI>Both the second and third operands have type std::nullptr_t or one
has that type and the other is a null pointer constant. The result is
of type std::nullptr_t.
</LI>
</UL>
</P>

</BLOCKQUOTE>

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