Title
[fund.ts.v2] Incorrect exception specifications for 'swap' in C++ Extensions for Library Fundamentals
Status
resolved
Section
[optional.object.swap][propagate_const.modifiers]
Submitter
Daniel Krügler

Created on 2015-12-11.00:00:00 last changed 28 months ago

Messages

Date: 2022-07-28.00:00:00

[ 2022-07-28 Resolved by P0966R1 and LWG 3413. Status changed: New → Resolved. ]

Date: 2020-03-15.00:00:00

[ 2020-03-30; Daniel comments ]

This has strong overlap with LWG 3413, which describes a sub-set of the problem here. Rebasing of the library fundamentals on C++20 has removed the mentioned problem for optionals free swap, so there are now no longer any further free swap function templates with conditionally noexcept specifications except for propagate_const (but now handled by LWG 3413).

Date: 2016-11-15.00:00:00

[ 2016-11-08, Issaquah ]

Not adopted during NB comment resolution

Date: 2016-03-07.04:46:57
Add a link to

[ 2016-03, Jacksonville ]

Add a link to 2456
Date: 2016-02-15.00:00:00

[ 2016-02-20, Daniel comments ]

A recent paper update has been provided: P0185R0.

Date: 2016-02-15.00:00:00

[ 2016-02-20, Ville comments ]

Feedback from an implementation:

libstdc++ already applies the proposed resolution for propagate_const, but not for optional.

Date: 2015-12-11.00:00:00

Addresses: fund.ts.v2

As pointed out in N4511, the Library fundamentals are affected by a similar problem as described in LWG 2456. First, it is caused by optional's member swap ([optional.object.swap]):

void swap(optional<T>& rhs) noexcept(see below);

with

The expression inside noexcept is equivalent to:

is_nothrow_move_constructible_v<T> && noexcept(swap(declval<T&>(), declval<T&>()))

Again, the unqualified lookup for swap finds the member swap instead of the result of a normal argument-depending lookup, making this ill-formed.

A second example of such a problem recently entered the arena with the addition of the propagate_const template with another member swap ([propagate_const.modifiers]):

constexpr void swap(propagate_const& pt) noexcept(see below);

-2- The constant-expression in the exception-specification is noexcept(swap(t_, pt.t_)).

A working approach is presented in N4511. By adding a new trait to the standard library and referencing this by the library fundamentals (A similar approach had been applied in the file system specification where the quoted manipulator from C++14 had been referred to, albeit the file system specification is generally based on the C++11 standard), optional's member swap exception specification could be rephrased as follows:

The expression inside noexcept is equivalent to:

is_nothrow_move_constructible_v<T> && is_nothrow_swappable_v<T>noexcept(swap(declval<T&>(), declval<T&>()))

and propagate_const's member swap exception specification could be rephrased as follows:

constexpr void swap(propagate_const& pt) noexcept(see below);

-2- The constant-expression in the exception-specification is is_nothrow_swappable_v<T>noexcept(swap(t_, pt.t_)).

History
Date User Action Args
2022-07-28 12:27:44adminsetmessages: + msg12659
2022-07-28 12:27:44adminsetstatus: new -> resolved
2020-03-30 16:29:55adminsetmessages: + msg11184
2016-11-20 18:58:35adminsetmessages: + msg8653
2016-03-07 04:46:57adminsetmessages: + msg8004
2016-02-20 20:56:18adminsetmessages: + msg7983
2016-02-20 20:56:18adminsetmessages: + msg7982
2015-12-11 00:00:00admincreate