<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 2224</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="2224"></A><H4>2224.
  
Member subobjects and base-class casts
</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>C++17
 &#160;&#160;&#160;

 <B>Submitter: </B>Aaron Ballman
 &#160;&#160;&#160;

 <B>Date: </B>2016-01-13<BR>


<P>[Adopted at the February/March, 2017 meeting.]</P>



<P>The current wording of 7.6.1.9 [<A href="https://wg21.link/expr.static.cast#2">expr.static.cast</A>] paragraph 2 appears
to permit the following example:</P>

<PRE>
  struct B {
    int i;
  };

  struct D : B {
    int j;
    B b;
  };

  int main() {
    D d;

    B &amp;br = d.b;
    D &amp;dr = static_cast&lt;D&amp;&gt;(br);  //<SPAN CLASS="cmnt"> Okay?</SPAN>
  }
</PRE>

<P>Presumably such casts should only be supported if the operand
object is a base class subobject, not a member subobject.</P>

<P><B>Proposed resolution (January, 2017):</B></P>

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

<BLOCKQUOTE>

...If the object of type &#8220;<I>cv1</I> <TT>B</TT>&#8221; is actually
a <INS>base class</INS> subobject of an object of type <TT>D</TT>, the
result refers to the enclosing object of type <TT>D</TT>. Otherwise, the
behavior is undefined. [<I>Example:</I>...

</BLOCKQUOTE>

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