Title
Incorrect exception specifications for 'swap' throughout library
Status
resolved
Section
[utility][pairs.pair][tuple] [array][queue][priority.queue] [stack]
Submitter
Richard Smith

Created on 2014-11-14.00:00:00 last changed 98 months ago

Messages

Date: 2016-03-07.05:48:12

[ 2016-03, Jacksonville ]

P0185R1 was adopted in Jacksonville.
Date: 2015-12-15.00:00:00

[ 2015-12-16, Daniel comments ]

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

Date: 2015-10-21.20:56:18

[ 2015-10, Kona, Daniel comments ]

A revised paper (N4511) has been provided

Date: 2015-05-05.18:15:15

[ 2015-05, Lenexa ]

Move to Open.

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

Date: 2015-03-28.16:52:16

[ 2015-02, Cologne ]

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

Date: 2014-11-14.00:00:00

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 [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 [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.

History
Date User Action Args
2016-03-07 05:48:12adminsetmessages: + msg8010
2016-03-07 05:48:12adminsetstatus: open -> resolved
2015-12-16 18:40:34adminsetmessages: + msg7647
2015-10-21 20:56:18adminsetmessages: + msg7580
2015-05-05 18:15:15adminsetmessages: + msg7349
2015-05-05 18:15:15adminsetstatus: new -> open
2015-03-28 16:52:16adminsetmessages: + msg7252
2014-11-14 00:00:00admincreate