<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2795: &sect;[global.functions] provides incorrect example of ADL use</title>
<meta property="og:title" content="Issue 2795: &sect;[global.functions] provides incorrect example of ADL use">
<meta property="og:description" content="C++ library issue. Status: C++17">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2795.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++17">C++17</a> status.</em></p>
<h3 id="2795"><a href="lwg-defects.html#2795">2795</a>. &sect;[global.functions] provides incorrect example of ADL use</h3>
<p><b>Section:</b> 16.4.6.4 <a href="https://wg21.link/global.functions">[global.functions]</a> <b>Status:</b> <a href="lwg-active.html#C++17">C++17</a>
 <b>Submitter:</b> Jonathan Wakely <b>Opened:</b> 2016-11-09 <b>Last modified:</b> 2017-07-30</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View all other</b> <a href="lwg-index.html#global.functions">issues</a> in [global.functions].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++17">C++17</a> status.</p>
<p><b>Discussion:</b></p>
<p>
<b>Addresses GB 39</b>
<p/>
The example is supposed to highlight the 'otherwise specified' 
aspect of invoking ADL, yet there is no such specification. It is 
unlikely that we intend to explicitly qualify calls to operator functions, 
so they probably should be exempted from this restriction.
<p/>
Suggested resolution:
<p/>
Fix example (and referenced clause) to specify use of ADL, or exempt operators from 
this clause, and find a better example, probably using <code>swap</code>.
</p>

<p><i>[2016-11-09, Jonathan comments and provides wording]</i></p>

<p>
The current wording was added by DR <a href="lwg-defects.html#225" title="std:: algorithms use of other unqualified algorithms (Status: CD1)">225</a><sup><a href="https://cplusplus.github.io/LWG/issue225" title="Latest snapshot">(i)</a></sup>.
</p>

<p><i>[2016-11-10, Tim Song comments]</i></p>

<p>
The "non-operator" seems to have been added at the wrong spot. The problem at issue is permission 
to call operator functions found via ADL, not permission for operator functions in the standard 
library to ADL all over the place. The problem is not unique to operator functions in the standard 
library &mdash; a significant portion of <code>&lt;algorithm&gt;</code> and <code>&lt;numeric&gt;</code> 
uses some operator (<code>==</code>, <code>&lt;</code>, <code>+</code>, <code>*</code>, etc.) that may be picked 
up via ADL.
<p/>
There is also an existing problem in that the example makes no sense anyway: the constraint in this 
paragraph only applies to non-members, yet <code>ostream_iterator::operator=</code> is a member function.
</p>

<p><i>[2016-11-10, Tim Song and Jonathan agree on new wording]</i></p>

<p>
The new wording still doesn't quite get it right:
</p>
<blockquote><p>
"calls to non-operator, non-member functions in the standard library do not use functions from another namespace 
which are found through argument-dependent name lookup" can be interpreted as saying that if a user writes 
"<code>std::equal(a, b, c, d)</code>", that call will not use ADL'd "<code>operator==</code>" because 
"<code>std::equal(a, b, c, d)</code>" is a "call" to a "non-operator, non-member function in the standard library".
</p></blockquote>
<p>
The key point here is that "in the standard library" should be modifying "calls", not "function".
</p>

<p>
<strong>Previous resolution [SUPERSEDED]:</strong>
</p>
<blockquote class="note">
<p>This wording is relative to N4606.</p>

<ol>
<li><p>Change 16.4.6.4 <a href="https://wg21.link/global.functions">[global.functions]</a> p4:</p>
<blockquote>
<p>
Unless otherwise specified, <ins>non-operator,</ins> non-member functions in the standard library shall not use functions from
another namespace which are found through argument-dependent name lookup (3.4.2). [<i>Note:</i> The phrase
"unless otherwise specified" <ins>applies to cases such as the swappable with requirements (16.4.4.3 <a href="https://wg21.link/swappable.requirements">[swappable.requirements]</a>). 
The exception for overloaded operators allows</ins><del>is intended to allow</del> argument-dependent lookup in cases like that of 
<code>ostream_iterator::operator=</code> (24.6.2.2):
</p>
<blockquote>
<p>
<i>Effects:</i>
</p>
<blockquote>
<pre>
*out_stream &lt;&lt; value;
if (delim != 0)
  *out_stream &lt;&lt; delim ;
return *this;
</pre>
</blockquote>
<p>
&mdash; <i>end note</i>]
</p>
</blockquote>
</blockquote>
</li>
</ol>

</blockquote>

<p><i>[Issues Telecon 16-Dec-2016]</i></p>

<p>Move to Tentatively Ready</p>


<p id="res-2795"><b>Proposed resolution:</b></p>
<p>This wording is relative to N4606.</p>

<ol>
<li><p>Change 16.4.6.4 <a href="https://wg21.link/global.functions">[global.functions]</a> p4:</p>
<blockquote>
<p>
Unless otherwise specified, <ins>calls made by functions in the standard library to non-operator,</ins> non-member functions 
 <del>in the standard library</del> <del>shall</del><ins>do</ins> not use functions from another namespace which are found through 
argument-dependent name lookup (3.4.2). [<i>Note:</i> The phrase "unless otherwise specified" <ins>applies to 
cases such as the swappable with requirements (16.4.4.3 <a href="https://wg21.link/swappable.requirements">[swappable.requirements]</a>). 
The exception for overloaded operators allows</ins><del>is intended to allow</del> argument-dependent lookup in cases like that of 
<code>ostream_iterator::operator=</code> (24.6.2.2):
</p>
<blockquote>
<p>
<i>Effects:</i>
</p>
<blockquote>
<pre>
*out_stream &lt;&lt; value;
if (delim != 0)
  *out_stream &lt;&lt; delim ;
return *this;
</pre>
</blockquote>
<p>
&mdash; <i>end note</i>]
</p>
</blockquote>
</blockquote>
</li>
</ol>





</body>
</html>
