<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 519</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="519"></A><H4>519.
  
Null pointer preservation in <TT>void*</TT> conversions
</H4>
<B>Section: </B>7.3.12&#160; [<A href="https://wg21.link/conv.ptr">conv.ptr</A>]
 &#160;&#160;&#160;

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

 <B>Submitter: </B>comp.std.c++
 &#160;&#160;&#160;

 <B>Date: </B>19 May 2005<BR>


<P>[Voted into WP at April, 2006 meeting.]</P>

<P>The C standard says in 6.3.2.3, paragraph 4:</P>

<BLOCKQUOTE>

Conversion of a null pointer to another pointer type yields a null
pointer of that type. Any two null pointers shall compare equal.

</BLOCKQUOTE>

<P>C++ appears to be incompatible with the first sentence in only two
areas:</P>

<PRE>
    A *a = 0;
    void *v = a;
</PRE>

<P>C++ (7.3.12 [<A href="https://wg21.link/conv.ptr#2">conv.ptr</A>] paragraph 2) says nothing about the
value of <TT>v</TT>.</P>

<PRE>
    void *v = 0;
    A *b = (A*)v; // aka static_cast&lt;A*&gt;(v)
</PRE>

<P>C++ (7.6.1.9 [<A href="https://wg21.link/expr.static.cast#10">expr.static.cast</A>] paragraph 10) says nothing about
the value of <TT>b</TT>.</P>

<P>
<U>Suggested changes</U>:</P>

<OL>

<LI><P>Add the following sentence to 7.3.12 [<A href="https://wg21.link/conv.ptr#2">conv.ptr</A>] paragraph 2:
</P></LI>

<BLOCKQUOTE>

The null pointer value is converted to the null pointer value of the
destination type.

</BLOCKQUOTE>

<LI><P>Add the following sentence to 7.6.1.9 [<A href="https://wg21.link/expr.static.cast#10">expr.static.cast</A>] paragraph 10:
</P></LI>

<BLOCKQUOTE>

The null pointer value (7.3.12 [<A href="https://wg21.link/conv.ptr">conv.ptr</A>]) is converted
to the null pointer value of the destination type.

</BLOCKQUOTE>

</OL>

<P><B>Proposed resolution (October, 2005):</B></P>

<OL>
<LI><P>Add the indicated words to 7.3.12 [<A href="https://wg21.link/conv.ptr#2">conv.ptr</A>] paragraph 2:
</P></LI>

<BLOCKQUOTE>

An rvalue of type &#8220;pointer to <I>cv</I> <TT>T</TT>,&#8221; where
<TT>T</TT> is an object type, can be converted to an rvalue of type &#8220;pointer to
<I>cv</I> <TT>void</TT>&#8221;. The result of converting a &#8220;pointer to
<I>cv</I> <TT>T</TT>&#8221; to a &#8220;pointer
to <I>cv</I> <TT>void</TT>&#8221; points to the start of the storage
location where the object of type <TT>T</TT> resides, as if the object
is a most derived object (6.8.2 [<A href="https://wg21.link/intro.object">intro.object</A>]) of
type <TT>T</TT> (that is, not a base class subobject). <INS>The null
pointer value is converted to the null pointer value of the
destination type.</INS>

</BLOCKQUOTE>

<LI><P>Add the indicated words to 7.6.1.9 [<A href="https://wg21.link/expr.static.cast#11">expr.static.cast</A>] paragraph 11:
</P></LI>

<BLOCKQUOTE>

An rvalue of type &#8220;pointer to <I>cv1</I> <TT>void</TT>&#8221;
can be converted to an rvalue of type &#8220;pointer
to <I>cv2</I> <TT>T</TT>,&#8221; where <TT>T</TT> is an object type
and <i>cv2</i> is the same cv-qualification as, or greater
cv-qualification than, <I>cv1</I>. <INS>The null pointer value is
converted to the null pointer value of the destination type.</INS> A
value of type pointer to object converted to &#8220;pointer
to <I>cv</I> <TT>void</TT>&#8221; and back, possibly with different
cv-qualification, shall have its original value...

</BLOCKQUOTE>

</OL>

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