<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3655: The INVOKE operation and union types</title>
<meta property="og:title" content="Issue 3655: The INVOKE operation and union types">
<meta property="og:description" content="C++ library issue. Status: C++23">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3655.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#C++23">C++23</a> status.</em></p>
<h3 id="3655"><a href="lwg-defects.html#3655">3655</a>. The <code><i>INVOKE</i></code> operation and <code>union</code> types</h3>
<p><b>Section:</b> 22.10.4 <a href="https://wg21.link/func.require">[func.require]</a> <b>Status:</b> <a href="lwg-active.html#C++23">C++23</a>
 <b>Submitter:</b> Jiang An <b>Opened:</b> 2021-12-29 <b>Last modified:</b> 2023-11-22</p>
<p><b>Priority: </b>3
</p>
<p><b>View other</b> <a href="lwg-index-open.html#func.require">active issues</a> in [func.require].</p>
<p><b>View all other</b> <a href="lwg-index.html#func.require">issues</a> in [func.require].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++23">C++23</a> status.</p>
<p><b>Discussion:</b></p>
<p>
There are two cases of the <code><i>INVOKE</i></code> operation specified with <code>std::is_base_of_v</code> 
(22.10.4 <a href="https://wg21.link/func.require">[func.require]</a> (1.1), (1,4)), which means the following code snippet is ill-formed, as 
<code>std::is_base_of_v&lt;B, D&gt;</code> is <code>false</code> when either <code>B</code> or <code>D</code> is a 
<code>union</code> type.
</p>
<blockquote><pre>
union Foo { int x; };
static_assert(std::is_invocable_v&lt;int Foo::*, Foo&amp;&gt;);
</pre></blockquote>
<p>
Currently libstdc++ accepts this code, because it uses slightly different conditions that handle <code>union</code> 
types. libc++ and MSVC STL reject this code as specified in 22.10.4 <a href="https://wg21.link/func.require">[func.require]</a>.
<p/>
Should we change the conditions in 22.10.4 <a href="https://wg21.link/func.require">[func.require]</a> (1.1) and (1.4) to match libstdc++ and correctly 
handle <code>union</code> types?
</p>

<p><i>[2022-01-30; Reflector poll]</i></p>

<p>
Set priority to 3 after reflector poll.
</p>

<p><i>[2023-02-07; Jonathan adds wording]</i></p>

<p>This is a regression introduced by LWG <a href="lwg-defects.html#2219" title="INVOKE-ing a pointer to member with a reference_wrapper as the object expression (Status: C++17)">2219</a><sup><a href="https://cplusplus.github.io/LWG/issue2219" title="Latest snapshot">(i)</a></sup>.
In C++14 <code>std::result_of&lt;int Foo::*(Foo&amp;)&gt;::type</code>
was valid, because the <code><i>INVOKE</i></code> wording used to say
"<code>f</code> is a pointer to member data of a class <code>T</code>
and <code>t1</code> is an object of type <code>T</code>
or a reference to an object of type <code>T</code>
or a reference to an object of a type derived from <code>T</code>".
Since LWG 2219 we use <code>is_base_of</code> which is always false for
union types.
I don't think LWG 2219 intended to break this case, so we should fix it.
</p>

<p><strong>Previous resolution [SUPERSEDED]:</strong></p>
<blockquote class="note">
<p>
This wording is relative to <a href="https://wg21.link/N4928" title=" Working Draft, Standard for Programming Language C++">N4928</a>.
</p>

<ol>
<li><p>Modify 22.10.4 <a href="https://wg21.link/func.require">[func.require]</a> as indicated:</p>

<blockquote>
<p>-1-
Define <code><i>INVOKE</i>(f, t1, t2, &hellip;, tN)</code> as follows:
</p>
<ul>
<li>(1.1) &mdash;
<code>(t1.*f)(t2, &hellip;, tN)</code>
when <code>f</code> is a pointer to a member function of a class <code>T</code> and
<code>
<ins>is_same_v&lt;T, remove_cvref_t&lt;decltype(t1)&gt;&gt; ||</ins>
is_base_of_v&lt;T, remove_reference_t&lt;decltype(t1)&gt;&gt;</code>
is <code>true</code>;
</li>
<li>(1.2) &mdash;
<code>(t1.get().*f)(t2, &hellip;, tN)</code>
when <code>f</code> is a pointer to a member function of a class <code>T</code> and
<code>remove_cvref_t&lt;decltype(t1)&gt;</code>
is a specialization of <code>reference_wrapper</code>;
</li>
<li>(1.3) &mdash;
<code>((*t1).*f)(t2, &hellip;, tN)</code>
when <code>f</code> is a pointer to a member function of a class <code>T</code> and
<code>t1</code> does not satisfy the previous two items;
</li>
<li>(1.4) &mdash;
<code>t1.*f</code>
when <code>N == 1</code> and
<code>f</code> is a pointer to data member of a class <code>T</code> and
<code>
<ins>is_same_v&lt;T, remove_cvref_t&lt;decltype(t1)&gt;&gt; ||</ins>
is_base_of_v&lt;T, remove_reference_t&lt;decltype(t1)&gt;&gt;</code>
is <code>true</code>;
</li>
<li>(1.5) &mdash;
<code>t1.get().*f</code>
when <code>N == 1</code> and
<code>f</code> is a pointer to data member of a class <code>T</code> and
<code>remove_cvref_t&lt;decltype(t1)&gt;</code>
is a specialization of <code>reference_wrapper</code>;
</li>
<li>(1.6) &mdash;
<code>(*t1).*f</code>
when <code>N == 1</code> and
<code>f</code> is a pointer to data member of a class <code>T</code> and
<code>t1</code> does not satisfy the previous two items;
</li>
<li>(1.7) &mdash;
<code>f(t1, t2, &hellip;, tN)</code> in all other cases.
</li>
</ul>
</blockquote>
</li>
</ol>

</blockquote>

<p><i>[2023-02-07; Jonathan provides wording change requested by LWG]</i></p>

<p>Change <code>remove_reference_t</code> to <code>remove_cvref_t</code>.
<code>is_base_of</code> ignores cv-qualifiers, so this isn't necessary,
but just using the same transformation in both cases seems simpler to grok.
</p>

<p><i>[Issaquah 2023-02-07; LWG]</i></p>

<p>Move to Immediate for C++23</p>

<p><i>[2023-02-13 Approved at February 2023 meeting in Issaquah. Status changed: Immediate &rarr; WP.]</i></p>



<p id="res-3655"><b>Proposed resolution:</b></p>
<p>
This wording is relative to <a href="https://wg21.link/N4928" title=" Working Draft, Standard for Programming Language C++">N4928</a>.
</p>

<ol>
<li><p>Modify 22.10.4 <a href="https://wg21.link/func.require">[func.require]</a> as indicated:</p>

<blockquote>
<p>-1-
Define <code><i>INVOKE</i>(f, t1, t2, &hellip;, tN)</code> as follows:
</p>
<ul>
<li>(1.1) &mdash;
<code>(t1.*f)(t2, &hellip;, tN)</code>
when <code>f</code> is a pointer to a member function of a class <code>T</code> and
<code>
<ins>is_same_v&lt;T, remove_cvref_t&lt;decltype(t1)&gt;&gt; ||</ins>
is_base_of_v&lt;T, remove_<del>reference</del><ins>cvref</ins>_t&lt;decltype(t1)&gt;&gt;</code>
is <code>true</code>;
</li>
<li>(1.2) &mdash;
<code>(t1.get().*f)(t2, &hellip;, tN)</code>
when <code>f</code> is a pointer to a member function of a class <code>T</code> and
<code>remove_cvref_t&lt;decltype(t1)&gt;</code>
is a specialization of <code>reference_wrapper</code>;
</li>
<li>(1.3) &mdash;
<code>((*t1).*f)(t2, &hellip;, tN)</code>
when <code>f</code> is a pointer to a member function of a class <code>T</code> and
<code>t1</code> does not satisfy the previous two items;
</li>
<li>(1.4) &mdash;
<code>t1.*f</code>
when <code>N == 1</code> and
<code>f</code> is a pointer to data member of a class <code>T</code> and
<code>
<ins>is_same_v&lt;T, remove_cvref_t&lt;decltype(t1)&gt;&gt; ||</ins>
is_base_of_v&lt;T, remove_<del>reference</del><ins>cvref</ins>_t&lt;decltype(t1)&gt;&gt;</code>
is <code>true</code>;
</li>
<li>(1.5) &mdash;
<code>t1.get().*f</code>
when <code>N == 1</code> and
<code>f</code> is a pointer to data member of a class <code>T</code> and
<code>remove_cvref_t&lt;decltype(t1)&gt;</code>
is a specialization of <code>reference_wrapper</code>;
</li>
<li>(1.6) &mdash;
<code>(*t1).*f</code>
when <code>N == 1</code> and
<code>f</code> is a pointer to data member of a class <code>T</code> and
<code>t1</code> does not satisfy the previous two items;
</li>
<li>(1.7) &mdash;
<code>f(t1, t2, &hellip;, tN)</code> in all other cases.
</li>
</ul>
</blockquote>
</li>
</ol>





</body>
</html>
