<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3441: Misleading note about calls to customization points</title>
<meta property="og:title" content="Issue 3441: Misleading note about calls to customization points">
<meta property="og:description" content="C++ library issue. Status: C++23">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3441.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="3441"><a href="lwg-defects.html#3441">3441</a>. Misleading note about calls to customization points</h3>
<p><b>Section:</b> 16.4.5.2.1 <a href="https://wg21.link/namespace.std">[namespace.std]</a> <b>Status:</b> <a href="lwg-active.html#C++23">C++23</a>
 <b>Submitter:</b> Michael Park <b>Opened:</b> 2020-05-08 <b>Last modified:</b> 2023-11-22</p>
<p><b>Priority: </b>1
</p>
<p><b>View other</b> <a href="lwg-index-open.html#namespace.std">active issues</a> in [namespace.std].</p>
<p><b>View all other</b> <a href="lwg-index.html#namespace.std">issues</a> in [namespace.std].</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>
<a href="https://wg21.link/p0551">P0551</a> (Thou Shalt Not Specialize <code>std</code> Function Templates!) 
added a clause in [namespace.std]/7:
</p>
<blockquote style="border-left: 3px solid #ccc;padding-left: 15px;">
<p>
Other than in namespace <code>std</code> or in a namespace within namespace <code>std</code>, a program may provide 
an overload for any library function template designated as a customization point, provided that 
(a) the overload's declaration depends on at least one user-defined type and (b) the overload meets 
the standard library requirements for the customization point. (footnote 174) [<i>Note:</i> This permits a (qualified 
or unqualified) call to the customization point to invoke the most appropriate overload for 
the given arguments. &mdash; <i>end note</i>]
</p>
</blockquote>
<p>
Given that <code>std::swap</code> is a designated customization point, the note seems to suggest the following:
</p>
<blockquote><pre>
namespace N {
  struct X {};
  void swap(X&amp;, X&amp;) {}
}

N::X a, b;
std::swap(a, b); // <span style="color:#C80000;font-weight:bold">qualified call to customization point finds N::swap?</span>
</pre></blockquote>
<p>
This is not what happens, as the call to <code>std::swap</code> does not find <code>N::swap</code>.
</p>

<p><i>[2020-07-17; Priority set to 1 in telecon]</i></p>

<p>Related to <a href="lwg-defects.html#3442" title="Unsatisfiable suggested implementation of customization points (Status: Resolved)">3442</a><sup><a href="https://cplusplus.github.io/LWG/issue3442" title="Latest snapshot">(i)</a></sup>.</p>

<p><i>[2020-09-11; discussed during telecon]</i></p>

<p>The note is simply bogus, not backed up by anything normative.
The normative part of the paragraph is an unacceptable landgrab on those
identifiers.
We have no right telling users they can't use the names <code>data</code>
and <code>size</code> unless they do exactly what we say <code>std::data</code>
and <code>std::size</code> do.
The library only ever uses <code>swap</code> unqualified, so the effect of
declaring the others as designated customization points is unclear.
</p>
<p>
The rule only needs to apply to such overloads <em>when actually found
by overload resolution</em> in a context that expects the semantics of
the customization point.
</p>
<p>
Frank: do we need to designate <code>operator&lt;&lt;</code> as a
customization point?  Users overload that in their own namespaces all the time.
</p>
<p>
Walter: This clearly needs a paper.
</p>

<p><i>[2020-10-02; status to Open]</i></p>


<p><strong>Previous resolution [SUPERSEDED]:</strong></p>
<blockquote class="note">
<p>This wording is relative to <a href="https://wg21.link/n4861">N4861</a>.</p>

<ol>
<li><p>Modify 16.4.5.2.1 <a href="https://wg21.link/namespace.std">[namespace.std]</a> as indicated:</p>

<blockquote>
<p>
-7- Other than in namespace <code>std</code> or in a namespace within namespace <code>std</code>, a program 
may provide an overload for any library function template designated as a customization point, 
provided that (a) the overload's declaration depends on at least one user-defined type and (b) the 
overload meets the standard library requirements for the customization point. (footnote 173) 
<del>[<i>Note:</i> This permits a (qualified or unqualified) call to the customization point
to invoke the most appropriate overload for the given arguments. &mdash; <i>end note</i>]</del>
</p>
</blockquote>
</li>

</ol>
</blockquote>

<p><i>[Issaquah 2023-02-09; Jonathan provides improved wording]</i></p>

<p>The normative part of 16.4.5.2.1 <a href="https://wg21.link/namespace.std">[namespace.std]</a> paragraph 7
(i.e. not the note and the footnote) does not actually do anything
except tell users they're not allowed to use the names
<code>begin</code>, <code>size</code> etc. unless they conform to the
provisions of paragraph 7. This means a program that contains the
following declaration might have undefined behaviour:
<pre><code>namespace user { int data(int, int); }</code></pre>
This is not OK! It's not even clear what "the requirements for
the customization point" are, if users wanted to meet them.
It's not even clear what "provide an overload" means.
</p>
<p>In particular, paragraph 7 does not give permission for the
designated customization points to actually <i>use</i> such
overloads. Just by forbidding users from using <code>data</code>
for their own functions isn't sufficient to allow the library to
use ADL to call <code>data</code>, and it's unclear why we'd want
that anyway (what problem with <code>std::data</code> are we trying
to solve that way?). As shown in LWG <a href="lwg-defects.html#3442" title="Unsatisfiable suggested implementation of customization points (Status: Resolved)">3442</a><sup><a href="https://cplusplus.github.io/LWG/issue3442" title="Latest snapshot">(i)</a></sup>, if
<code>std::data</code> became a customization point that would be
a backwards-incompatible change, and create a portability problem
if some implementations did that and others didn't.
</p>
<p>So the non-normative note and footnote make claims that do not
follow from the normative wording, and should be removed.</p>

<p>The only one of the designated customization points that
is actually looked up using ADL is <code>std::swap</code>, but how that
works is fully specified by 16.4.2.2 <a href="https://wg21.link/contents">[contents]</a> and
16.4.4.3 <a href="https://wg21.link/swappable.requirements">[swappable.requirements]</a>. The additional specification
that it's a designated customization point serves no benefit.
In particular, the permission that the note and footnote claim
exists is not needed. We specify precisely how <code>swap</code>
calls are performed.
We don't even need to say that user overloads of <code>swap</code>
in their own namespaces must meet the library requirements,
because the "swappable with" and <i>Cpp17Swappable</i> requirements
state the required semantics, and functions that use <code>swap</code>
have preconditions that the types are swappable. So we correctly
impose preconditions <b>in the places that actually call swap</b>,
and don't need to globally make it undefined for any function
called <code>swap</code> to not meet the requirements, even if that
function is never found by ADL by the library (e.g. because it's
in a namespace that is never an associated namespace of any types
used with library components that require swappable types).
</p>
<p>Paragraph 7 and its accompanying notes should go.</p>

<p><i>[Issaquah 2023-02-09; 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-3441"><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 16.4.5.2.1 <a href="https://wg21.link/namespace.std">[namespace.std]</a> as indicated:</p>

<blockquote class="note">[<i>Drafting note</i>:
This should also remove the only index entry for "customization point".
]</blockquote>

<blockquote>
<p><del>-7-
Other than in namespace <code>std</code> or in a namespace within namespace <code>std</code>,
a program may provide an overload for any library function template designated as a
<i>customization point</i>, provided that
(a) the overload's declaration depends on at least one user-defined type and
(b) the overload meets the standard library requirements for the customization point.
<sup>163</sup>
</del>
</p>
<p>
<del>
[<i>Note 3</i>:
This permits a (qualified or unqualified) call to the customization point
to invoke the most appropriate overload for the given arguments.
&mdash; <i>end note</i>]
</del>
</p>
<p>
<del>
163)
Any library customization point must be prepared to work adequately with
any user-defined overload that meets the minimum requirements of this document.
Therefore an implementation can elect, under the as-if rule
(6.10.1 <a href="https://wg21.link/intro.execution">[intro.execution]</a>), to provide any customization point
in the form of an instantiated function object (22.10 <a href="https://wg21.link/function.objects">[function.objects]</a>)
even though the customization point's specification is in the form of a function template.
The template parameters of each such function object and the function parameters
and return type of the object's <code>operator()</code> must match those of the
corresponding customization point's specification.
</del>
</p>
</blockquote>
</li>

<li><p>Modify 22.2.2 <a href="https://wg21.link/utility.swap">[utility.swap]</a> as indicated:</p>

<blockquote>
<pre><code>
template&lt;class T&gt;
  constexpr void swap(T&amp; a, T&amp; b) noexcept(<i>see below</i>);
</code></pre>
<p>-1- <i>Constraints</i>:
<code>is_move_constructible_v&lt;T&gt;</code> is <code>true</code>
and <code>is_move_assignable_v&lt;T&gt;</code> is <code>true</code>.
</p>
<p>-2- <i>Preconditions</i>:
Type <code>T</code> meets the <i>Cpp17MoveConstructible</i> (Table 32)
and <i>Cpp17MoveAssignable</i> (Table 34) requirements.
</p>
<p>-3- <i>Effects</i>:
Exchanges values stored in two locations.
</p>
<p>-4- <i>Remarks</i>:
<del>
This function is a designated customization point
(16.4.5.2.1 <a href="https://wg21.link/namespace.std">[namespace.std]</a>).
</del>
The exception specification is equivalent to:
<pre><code>
is_nothrow_move_constructible_v&lt;T&gt; &amp;&amp; is_nothrow_move_assignable_v&lt;T&gt;
</code></pre>
</p>
</blockquote>
</li>

<li><p>Modify 24.7 <a href="https://wg21.link/iterator.range">[iterator.range]</a> as indicated:</p>

<blockquote>
<p>-1-
In addition to being available via inclusion of the &lt;iterator&gt; header,
the function templates in 24.7 <a href="https://wg21.link/iterator.range">[iterator.range]</a> are available when
any of the following headers are included:
&lt;array&gt; (23.3.2 <a href="https://wg21.link/array.syn">[array.syn]</a>),
&lt;deque&gt; (23.3.4 <a href="https://wg21.link/deque.syn">[deque.syn]</a>),
&lt;forward_list&gt; (23.3.6 <a href="https://wg21.link/forward.list.syn">[forward.list.syn]</a>),
&lt;list&gt; (23.3.10 <a href="https://wg21.link/list.syn">[list.syn]</a>),
&lt;map&gt; (23.4.2 <a href="https://wg21.link/associative.map.syn">[associative.map.syn]</a>),
&lt;regex&gt; (28.6.3 <a href="https://wg21.link/re.syn">[re.syn]</a>),
&lt;set&gt; (23.4.5 <a href="https://wg21.link/associative.set.syn">[associative.set.syn]</a>),
&lt;span&gt; (23.7.2.1 <a href="https://wg21.link/span.syn">[span.syn]</a>),
&lt;string&gt; (27.4.2 <a href="https://wg21.link/string.syn">[string.syn]</a>),
&lt;string_view&gt; ( [string.view.syn]),
&lt;unordered_map&gt; (23.5.2 <a href="https://wg21.link/unord.map.syn">[unord.map.syn]</a>),
&lt;unordered_set&gt; (23.5.5 <a href="https://wg21.link/unord.set.syn">[unord.set.syn]</a>),
and &lt;vector&gt; (23.3.12 <a href="https://wg21.link/vector.syn">[vector.syn]</a>).
<del>
Each of these templates is a designated customization point
(16.4.5.2.1 <a href="https://wg21.link/namespace.std">[namespace.std]</a>).
</del>
</p>
</blockquote>
</li>
</ol>





</body>
</html>
