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

4047. Explicitly specifying template arguments for std::swap should not be supported

Section: 16.4.5.2.1 [namespace.std] Status: New Submitter: Jiang An Opened: 2024-01-25 Last modified: 2024-03-15

Priority: 4

View other active issues in [namespace.std].

View all other issues in [namespace.std].

View all issues with New status.

Discussion:

std::swap overloads are separately declared in many standard library headers. It is likely expected that when a program includes correct headers for standard library types to be swapped, a std::swap call, with template argument deduced from arguments, selects the correct overload.

However, if one explicitly specifies template arguments for a std::swap call, there would be possibly undesired overloads for which templates arguments are fully obtained, and thus undesired instantiation and ill-formed may be triggered.

Perhaps we should explicitly state that explicitly specifying templates for std::swap is unsupported (having unspecified effects and possibly ill-formed), like taking address of non-address functions (16.4.5.2.1 [namespace.std]/6) and explicitly specifying template arguments for most standard algorithms (27.2 [algorithms.requirements]/15), to avoid possible reading that there are some guarantees, derived from signatures of overloads, for doing so.

[2024-03-15; Reflector poll]

Set priority to 4 after reflector poll.

NAD - if a user does this and it breaks, so be it.

NAD as an issue creating a new kind of library policy for the first time. Needs a paper.

Not unique to std::swap. We should forbid this throughout the standard library.

Closely related to LWG 2146.

Proposed resolution: