<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 2606</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="2606"></A><H4>2606.
  
<TT>static_cast</TT> from "pointer to void" does not handle similar types
</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>CD6
 &#160;&#160;&#160;

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

 <B>Date: </B>2022-06-28<BR>


<P>[Accepted at the July, 2022 meeting.]</P>

<P>Consider:</P>

<PRE>
  struct S {
    int a[5];
  } s;
  int (*p)[] = reinterpret_cast&lt;int(*)[]&gt;(&amp;s);
  int n = (*p)[0];
</PRE>

<P>This ought to have defined behavior: a pointer to <TT>s</TT> and a
pointer to <TT>s.a</TT> are pointer-interconvertible, so you should be
able to navigate between them this way. But the cast as shown does not
work, because the type of the pointer-interconvertible object
is <TT>int[5]</TT>, not <TT>int[]</TT>.</P>

<P><B>Proposed resolution (approved by CWG 2022-07-01):</B></P>

<P>Change in 7.6.1.9 [<A href="https://wg21.link/expr.static.cast#13">expr.static.cast</A>] paragraph 13 as follows:</P>

<BLOCKQUOTE>

... Otherwise, if the original pointer value points to an object a,
and there is an object b of type <INS>similar
to</INS> <TT>T</TT> <DEL>(ignoring cv-qualification)</DEL> that is
pointer-interconvertible (6.9.4 [<A href="https://wg21.link/basic.compound">basic.compound</A>]) with a, the
result is a pointer to b. Otherwise, the pointer value is unchanged by
the conversion.

</BLOCKQUOTE>

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