This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of Resolved status.

2456. Incorrect exception specifications for 'swap' throughout library

Section: 22.2 [utility], 22.3.2 [pairs.pair], 22.4 [tuple], 23.3.3 [array], 23.6.3 [queue], 23.6.4 [priority.queue], 23.6.6 [stack] Status: Resolved Submitter: Richard Smith Opened: 2014-11-14 Last modified: 2016-03-07

Priority: 1

View all other issues in [utility].

View all issues with Resolved status.

Discussion:

We have this antipattern in various library classes:

void swap(priority_queue& q) noexcept(
    noexcept(swap(c, q.c)) && noexcept(swap(comp, q.comp)))

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.

Relevant history on the core language side:

This used to be ill-formed due to 6.4.7 [basic.scope.class] p1 rule 2: "A name N used in a class S shall refer to the same declaration in its context and when re-evaluated in the completed scope of S. No diagnostic is required for a violation of this rule."

Core issue 1330 introduced delay-parsing for exception specifications. Due to the 6.4.7 [basic.scope.class] 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.

Suggested resolution:

Add an is_nothrow_swappable trait, and use it throughout the library in place of these noexcept expressions.

[2015-02, Cologne]

No action for now; we intend to have papers for Lenexa.

[2015-05, Lenexa]

Move to Open.

Daniel: A first paper (N4426) exists to suggest some ways of solving this issue.

[2015-10, Kona, Daniel comments]

A revised paper (N4511) has been provided

[2015-12-16, Daniel comments]

Revision 2 (P0185R0) will available for the mid February 2016 mailing.

[2016-03, Jacksonville]

P0185R1 was adopted in Jacksonville.

Proposed resolution: