Title
std::optional<T&>::swap possibly selects ADL-found `swap`
Status
wp
Section
[optional.ref.swap]
Submitter
Jiang An

Created on 2025-10-31.00:00:00 last changed 1 week ago

Messages

Date: 2025-11-11.10:48:55

Proposed resolution:

This wording is relative to N5014.

  1. Modify [optional.ref.swap] as indicated:

    constexpr void swap(optional& rhs) noexcept;
    

    -1- Effects: Equivalent to: std::swap(val, rhs.val).

Date: 2025-11-11.10:48:55

[ Kona 2025-11-08; Status changed: Immediate → WP. ]

Date: 2025-11-07.19:33:31

[ Kona 2025-11-07; approved by LWG. Status changed: New → Immediate. ]

Date: 2025-10-31.00:00:00

Currently, [optional.ref.swap] p1 specifies an "unqualified" `swap` call, which possibly selects an ADL-found swap function due to [contents] and [swappable.requirements].

It's unlike to be intentional to call ADL-found `swap` on pointers (given `ranges::swap` doesn't), and the unconditional `noexcept` also suggests that user-provided `swap` functions shouldn't interfere with optional<T&>::swap.

History
Date User Action Args
2025-11-11 10:48:55adminsetmessages: + msg15692
2025-11-11 10:48:55adminsetstatus: immediate -> wp
2025-11-07 19:33:31adminsetmessages: + msg15596
2025-11-07 19:33:31adminsetstatus: new -> immediate
2025-10-31 12:08:12adminsetmessages: + msg15479
2025-10-31 00:00:00admincreate