<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 2882</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="2882"></A><H4>2882.
  
Unclear treatment of conversion to <TT>void</TT>
</H4>
<B>Section: </B>7.6.1.9&#160; [<A href="https://wg21.link/expr.static.cast">expr.static.cast</A>]
 &#160;&#160;&#160;

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

 <B>Submitter: </B>Richard Smith
 &#160;&#160;&#160;

 <B>Date: </B>2024-04-24<BR>


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



<P>The ordering of paragraphs in 7.6.1.9 [<A href="https://wg21.link/expr.static.cast">expr.static.cast</A>] appears
to imply that an attempt is made to form an implicit conversion
sequence for conversions to <TT>void</TT>, possibly considering
user-defined conversion functions to <TT>void</TT>.  This is not
intended.</P>

<P><B>Proposed resolution (approved by CWG 2024-05-31):</B></P>

<OL>
<LI>
<P>Move 7.6.1.9 [<A href="https://wg21.link/expr.static.cast#6">expr.static.cast</A>] paragraph 6 to before paragraph 4,
strike paragraph 5, and adjust paragraph 7:</P>

<BLOCKQUOTE>

<P class="ins">Any expression can be explicitly converted to type <I>cv</I>
<TT>void</TT>, in which case the operand is a discarded-value expression
(7.2 [<A href="https://wg21.link/expr.prop">expr.prop</A>]).  [<I>Note 3:</I> Such a static_cast has no
result as it is a prvalue of type void; see
7.2.1 [<A href="https://wg21.link/basic.lval">basic.lval</A>]. &#8212;<I>end note</I>]
[<I>Note 4:</I> However, if the value is in a temporary
object (6.8.7 [<A href="https://wg21.link/class.temporary">class.temporary</A>]), the destructor for that object is
not executed until the usual time, and the value of the object is
preserved for the purpose of executing the destructor. &#8212;<I>end
note</I>]
</P>

<P>
<DEL>An</DEL> <INS>Otherwise, an</INS> expression E can be
explicitly converted to a type T if there is an implicit conversion
sequence (12.2.4.2 [<A href="https://wg21.link/over.best.ics">over.best.ics</A>]) from E to T, if overload
resolution ...</P>

<P class="del">Otherwise, the static_cast shall perform one of the
conversions listed below. No other conversion shall be performed
explicitly using a static_cast.</P>

<P class="del">Any expression can be explicitly converted to type cv
void, in which case the operand is a discarded-value expression
(7.2 [<A href="https://wg21.link/expr.prop">expr.prop</A>]).  [<I>Note 3:</I> Such a static_cast has no
result as it is a prvalue of type void; see
7.2.1 [<A href="https://wg21.link/basic.lval">basic.lval</A>]. &#8212;<I>end note</I>]
[<I>Note 4:</I> However, if the value is in a temporary
object (6.8.7 [<A href="https://wg21.link/class.temporary">class.temporary</A>]), the destructor for that object is
not executed until the usual time, and the value of the object is
preserved for the purpose of executing the destructor. &#8212;<I>end
note</I>]
</P>

<P>
<DEL>The</DEL> <INS>Otherwise, the</INS> inverse
of <DEL>any</DEL> <INS>a</INS> standard conversion sequence
(7.3 [<A href="https://wg21.link/conv">conv</A>]) not containing an lvalue-to-rvalue
(7.3.2 [<A href="https://wg21.link/conv.lval">conv.lval</A>]), array-to-pointer
(7.3.3 [<A href="https://wg21.link/conv.array">conv.array</A>]), function-to-pointer
(7.3.4 [<A href="https://wg21.link/conv.func">conv.func</A>]), null pointer
(7.3.12 [<A href="https://wg21.link/conv.ptr">conv.ptr</A>]), null member pointer
(7.3.13 [<A href="https://wg21.link/conv.mem">conv.mem</A>]), boolean (7.3.15 [<A href="https://wg21.link/conv.bool">conv.bool</A>]),
or function pointer (7.3.14 [<A href="https://wg21.link/conv.fctptr">conv.fctptr</A>]) conversion, can be
performed explicitly using static_cast. A program is ill-formed if it
uses static_cast to perform the inverse of an ill-formed standard
conversion sequence.
</P>

</BLOCKQUOTE>
</LI>

<LI>
<P>Add a new paragraph after 7.6.1.9 [<A href="https://wg21.link/expr.static.cast#14">expr.static.cast</A>] paragraph 14:</P>

<BLOCKQUOTE>

<P>A prvalue of type &#8220;pointer to cv1 void&#8221; can be
converted to a prvalue of type &#8220;pointer to cv2 T&#8221;, ...
Otherwise, the pointer value is unchanged by the conversion.
[<I>Example 3:</I> ...  &#8212;<I>end example</I>]
</P>

<P class="ins">
No other conversion can be performed using <TT>static_cast</TT>.
</P>

</BLOCKQUOTE>

</LI>
</OL>

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