<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 4007: Mystic prohibition of calling a volatile-qualified perfect forwarding call wrapper</title>
<meta property="og:title" content="Issue 4007: Mystic prohibition of calling a volatile-qualified perfect forwarding call wrapper">
<meta property="og:description" content="C++ library issue. Status: New">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue4007.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#New">New</a> status.</em></p>
<h3 id="4007"><a href="lwg-active.html#4007">4007</a>. Mystic prohibition of calling a <code>volatile</code>-qualified perfect forwarding call wrapper</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#New">New</a>
 <b>Submitter:</b> Jiang An <b>Opened:</b> 2023-11-05 <b>Last modified:</b> 2024-03-11</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#New">New</a> status.</p>
<p><b>Discussion:</b></p>
<p>
22.10.4 <a href="https://wg21.link/func.require">[func.require]</a>/4 says:
</p>
<blockquote><p>
[&hellip;] This forwarding step delivers a state entity of type <code>T</code> as <i>cv</i> <code>T&amp;</code> 
when the call is performed on an lvalue of the call wrapper type and as <i>cv</i> <code>T&amp;&amp;</code> 
otherwise, where <i>cv</i> represents the cv-qualifiers of the call wrapper and where <i>cv</i> shall 
be neither <code>volatile</code> nor <code>const volatile</code>.
</p></blockquote>
<p>
The "shall" seemingly indicates a requirement for user codes that calling a volatile perfect forwarding 
call wrapper is undefined behavior. Such requirement seems to be combined with requirements for 
implementations in an unusual way.
<p/>
Moreover, it is unclear whether UB is intended here. Perhaps we only want calling such a <code>volatile</code> 
wrapper to be conditionally-supported. E.g. when the <code>operator()</code> happens to be implementable as a 
static member function, calling a <code>volatile</code> wrapper can be naturally supported and have expected 
behavior.
</p>

<p><i>[2024-03-11; Reflector poll]</i></p>

<p>
Set priority to 3 after reflector poll.
</p>
<p>
LWG <a href="lwg-defects.html#2487" title="bind() should be const-overloaded, not cv-overloaded (Status: C++17)">2487</a><sup><a href="https://cplusplus.github.io/LWG/issue2487" title="Latest snapshot">(i)</a></sup> doesn't seem to intend to forbid <code>volatile</code>
support as a conforming extension.
</p>
<p>
<a href="https://wg21.link/P1065R2" title=" constexpr INVOKE">P1065R2</a> made it ill-formed for <code>std::bind</code> but didn't
make the same change to the definition of perfect forwarding call wrapper.
So given an <code class='backtick'>as_volatile</code> function that works like <code class='backtick'>std::as_const</code>,
<code>as_volatile(std::bind(&amp;T::fn))(t)</code> is ill-formed but
<code>as_volatile(std::mem_fn(&amp;T::fn))(t)</code> is undefined.
Supporting it as a conforming extension is fine, but making it UB is not.
Maybe "conditionally supported" instead?
</p>



<p id="res-4007"><b>Proposed resolution:</b></p>
<p>
This wording is relative to <a href="https://wg21.link/N4964" title=" Working Draft, Programming Languages — C++">N4964</a>.
</p>

<ol>

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

<blockquote>
<p>
4 A <i>perfect forwarding call wrapper</i> is an argument forwarding call wrapper that forwards its state entities
to the underlying call expression. This forwarding step delivers a state entity of type <code>T</code> as 
<i>cv</i> <code>T&amp;</code> when the call is performed on an lvalue of the call wrapper type and as <i>cv</i> 
<code>T&amp;&amp;</code> otherwise, where <i>cv</i> represents the cv-qualifiers of the call wrapper <del>and where 
<i>cv</i> shall be neither <code>volatile</code> nor <code>const volatile</code></del><ins>, except that if <i>cv</i> 
is either <code>volatile</code> or <code>const volatile</code>, it is unspecified whether the call is well-formed</ins>.
</p>
</blockquote>

</li>

</ol>





</body>
</html>
