<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3305: any_cast&lt;void&gt;</title>
<meta property="og:title" content="Issue 3305: any_cast&lt;void&gt;">
<meta property="og:description" content="C++ library issue. Status: WP">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3305.html">
<meta property="og:type" content="website">
<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png">
<meta property="og:image:alt" content="C++ logo">
<style>
  p {text-align:justify}
  li {text-align:justify}
  pre code.backtick::before { content: "`" }
  pre code.backtick::after { content: "`" }
  blockquote.note
  {
    background-color:#E0E0E0;
    padding-left: 15px;
    padding-right: 15px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
  ins {background-color:#A0FFA0}
  del {background-color:#FFA0A0}
  table.issues-index { border: 1px solid; border-collapse: collapse; }
  table.issues-index th { text-align: center; padding: 4px; border: 1px solid; }
  table.issues-index td { padding: 4px; border: 1px solid; }
  table.issues-index td:nth-child(1) { text-align: right; }
  table.issues-index td:nth-child(2) { text-align: left; }
  table.issues-index td:nth-child(3) { text-align: left; }
  table.issues-index td:nth-child(4) { text-align: left; }
  table.issues-index td:nth-child(5) { text-align: center; }
  table.issues-index td:nth-child(6) { text-align: center; }
  table.issues-index td:nth-child(7) { text-align: left; }
  table.issues-index td:nth-child(5) span.no-pr { color: red; }
  @media (prefers-color-scheme: dark) {
     html {
        color: #ddd;
        background-color: black;
     }
     ins {
        background-color: #225522
     }
     del {
        background-color: #662222
     }
     a {
        color: #6af
     }
     a:visited {
        color: #6af
     }
     blockquote.note
     {
        background-color: rgba(255, 255, 255, .10)
     }
  }
</style>
</head>
<body>
<hr>
<p><em>This page is a snapshot from the LWG issues list, see the <a href="lwg-active.html">Library Active Issues List</a> for more information and the meaning of <a href="lwg-active.html#WP">WP</a> status.</em></p>
<h3 id="3305"><a href="lwg-defects.html#3305">3305</a>. <code>any_cast&lt;void&gt;</code></h3>
<p><b>Section:</b> 22.7.5 <a href="https://wg21.link/any.nonmembers">[any.nonmembers]</a> <b>Status:</b> <a href="lwg-active.html#WP">WP</a>
 <b>Submitter:</b> John Shaw <b>Opened:</b> 2019-10-16 <b>Last modified:</b> 2023-11-22</p>
<p><b>Priority: </b>2
</p>
<p><b>View all other</b> <a href="lwg-index.html#any.nonmembers">issues</a> in [any.nonmembers].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#WP">WP</a> status.</p>
<p><b>Discussion:</b></p>
<blockquote><pre>
any foo;
void* p = any_cast&lt;void&gt;(&amp;foo);
</pre></blockquote>
<p>
Per 22.7.5 <a href="https://wg21.link/any.nonmembers">[any.nonmembers]</a>/9, since the operand isn't <code>nullptr</code> and 
<code>operand-&gt;type() == typeid(T)</code> (because <code>T = void</code> in this case), we should 
return a pointer to the object contained by <code>operand</code>. But there is no such object.
<p/>
We need to handle the <code>T = void</code> case, probably by just explicitly returning <code>nullptr</code>.
</p>

<p><i>[2019-11 Priority to 2 during Monday issue prioritization in Belfast. There is implementation divergence here.]</i></p>

<p><i>[2020-02 LWG discussion in Prague did not reach consensus. Status to Open.]</i></p>

<p>There was discussion about whether or not <code>any_cast&lt;void&gt;(a)</code> should be ill-formed, or return <code>nullptr</code>.</p>
<p>Poll "should it return nullptr" was 0-4-5-5-1.</p>
<p><i>[2022-02 Currently ill-formed in MSVC ("error C2338: std::any cannot contain void") and returns null pointer in libstdc++ and libc++.]</i></p>

<p><strong>Previous resolution [SUPERSEDED]:</strong></p>
<blockquote class="note">

<p>This wording is relative to <a href="https://wg21.link/n4835">N4835</a>.</p>

<ol>
<li><p>Modify 22.7.5 <a href="https://wg21.link/any.nonmembers">[any.nonmembers]</a> as indicated:</p>

<blockquote>
<pre>
template&lt;class T&gt;
  const T* any_cast(const any* operand) noexcept;
template&lt;class T&gt;
  T* any_cast(any* operand) noexcept;
</pre>
<blockquote>
<p>
-9- <i>Returns:</i> If <code>operand != nullptr &amp;&amp; operand-&gt;type() == typeid(T) <ins>&amp;&amp; 
is_object_v&lt;T&gt;</ins></code>, a pointer to the object contained by <code>operand</code>; otherwise, 
<code>nullptr</code>.
<p/>
[&hellip;]
</p>
</blockquote>
</blockquote>
</li>
</ol>

</blockquote>

<p><i>[2023-06-14 Varna; Jonathan provides improved wording]</i></p>

<p><i>[2023-06-14 Varna; Move to Ready]</i></p>

<p>Poll: 7-0-1</p>

<p><i>[2023-11-11 Approved at November 2023 meeting in Kona. Status changed: Voting &rarr; WP.]</i></p>



<p id="res-3305"><b>Proposed resolution:</b></p>

<p>This wording is relative to <a href="https://wg21.link/N4950" title=" Working Draft, Standard for Programming Language C++">N4950</a>.</p>

<ol>
<li><p>Modify 22.7.5 <a href="https://wg21.link/any.nonmembers">[any.nonmembers]</a> as indicated:</p>

<blockquote>
<pre>
template&lt;class T&gt;
  const T* any_cast(const any* operand) noexcept;
template&lt;class T&gt;
  T* any_cast(any* operand) noexcept;
</pre>
<blockquote>
<p>
<ins>
-8-
<i>Mandates</i>:
<code>is_void_v&lt;T&gt;</code> is <code>false</code>.
</ins>
</p>
<p>
-9-
<i>Returns</i>: If <code>operand != nullptr &amp;&amp; operand-&gt;type() == typeid(T)</code> <ins>is <code>true</code></ins>, a pointer to the object contained by <code>operand</code>; otherwise,
<code>nullptr</code>.
<p/>
[&hellip;]
</p>
</blockquote>
</blockquote>
</li>
</ol>





</body>
</html>
