<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2456: Incorrect exception specifications for 'swap' throughout library</title>
<meta property="og:title" content="Issue 2456: Incorrect exception specifications for 'swap' throughout library">
<meta property="og:description" content="C++ library issue. Status: Resolved">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2456.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#Resolved">Resolved</a> status.</em></p>
<h3 id="2456"><a href="lwg-defects.html#2456">2456</a>. Incorrect exception specifications for '<code>swap</code>' throughout library</h3>
<p><b>Section:</b> 22.2 <a href="https://wg21.link/utility">[utility]</a>, 22.3.2 <a href="https://wg21.link/pairs.pair">[pairs.pair]</a>, 22.4 <a href="https://wg21.link/tuple">[tuple]</a>, 23.3.3 <a href="https://wg21.link/array">[array]</a>, 23.6.3 <a href="https://wg21.link/queue">[queue]</a>, 23.6.4 <a href="https://wg21.link/priority.queue">[priority.queue]</a>, 23.6.6 <a href="https://wg21.link/stack">[stack]</a> <b>Status:</b> <a href="lwg-active.html#Resolved">Resolved</a>
 <b>Submitter:</b> Richard Smith <b>Opened:</b> 2014-11-14 <b>Last modified:</b> 2016-03-07</p>
<p><b>Priority: </b>1
</p>
<p><b>View all other</b> <a href="lwg-index.html#utility">issues</a> in [utility].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#Resolved">Resolved</a> status.</p>
<p><b>Discussion:</b></p>
<p>
We have this antipattern in various library classes:
</p>
<blockquote><pre>
void swap(priority_queue&amp; q) noexcept(
    noexcept(swap(c, q.c)) &amp;&amp; noexcept(swap(comp, q.comp)))
</pre></blockquote>
<p>
This doesn't work. The unqualified lookup for 'swap' finds the member named 'swap', and that suppresses ADL, 
so the exception specification is always ill-formed because you can't call the member 'swap' with two arguments.
<p/>
Relevant history on the core language side:
<p/>
This used to be ill-formed due to 6.4.7 <a href="https://wg21.link/basic.scope.class">[basic.scope.class]</a> p1 rule 2: "A name <code>N</code> used in a class 
<code>S</code> shall refer to the same declaration in its context and when re-evaluated in the completed scope of <code>S</code>. 
No diagnostic is required for a violation of this rule."
<p/>
Core issue 1330 introduced delay-parsing for exception specifications. Due to the 6.4.7 <a href="https://wg21.link/basic.scope.class">[basic.scope.class]</a> rules, 
this shouldn't have changed the behavior of any conforming programs. But it changes the behavior in the non-conforming 
case from "no diagnostic required" to "diagnostic required", so implementations that implement core issue 1330 are now 
required to diagnose the ill-formed declarations in the standard library.
<p/>
Suggested resolution:
<p/>
Add an <code>is_nothrow_swappable</code> trait, and use it throughout the library in place of these <code>noexcept</code> expressions.
</p>

<p><i>[2015-02, Cologne]</i></p>

<p>
No action for now; we intend to have papers for Lenexa.
</p>

<p><i>[2015-05, Lenexa]</i></p>

<p>
Move to Open.
<p/>
Daniel: A first paper (<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4426.html">N4426</a>) exists 
to suggest some ways of solving this issue.
</p>

<p><i>[2015-10, Kona, Daniel comments]</i></p>

<p>
A revised paper (<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4511.html">N4511</a>) has been provided 
</p>

<p><i>[2015-12-16, Daniel comments]</i></p>

<p>
Revision 2 (<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0185r0.html">P0185R0</a>) will available for the
mid February 2016 mailing.
</p>

<p><i>[2016-03, Jacksonville]</i></p>

<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0185r1.html">P0185R1</a> was adopted in Jacksonville.


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





</body>
</html>
