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.

4610. std::swap should specially handle std::locale

Section: 28.3.2 [locale.syn] Status: New Submitter: Jiang An Opened: 2026-07-31 Last modified: 2026-08-01

Priority: Not Prioritized

View all other issues in [locale.syn].

View all issues with New status.

Discussion:

Currently, std::locale lacks move functions, and std::swap uses copy constructor and copy assignment operator to swap locale objects according to the default mechanism.

The lack of move functions is possibly intended. Because in some implementations (at least for libc++ and libstdc++), some precondition-free functions are assuming that a valid locale object is always resource-holding, and it's possibly infeasible to establish a valid moved-from state for locale. However, it's pessimized to use copy functions to swap locale objects since this requires increments and decrements of reference counts in mainstream implementations. An optimized strategy might be just swapping the internal pointers, which doesn't need to touch reference counts.

It seems possible to optimize std::swap for locale without affecting overload resolution. So, this seems able to be done without tweaking the standard wording. However, some implementors think it's simpler to just add a new overload (see llvm/llvm-project#209760). This approach needs to tweak the standard wording because the effects of the new overload in overload resolution are observable.

Proposed resolution:

This wording is relative to N5054.

  1. Modify 28.3.2 [locale.syn] as indicated:

    namespace std {
      // 28.3.3.1 [locale], locale
      class locale;
      
      void swap(locale& lhs, locale& rhs) noexcept;
      
      template<class Facet> const Facet& use_facet(const locale&);
      template<class Facet> bool has_facet(const locale&) noexcept;
      […]
    }
    
  2. Add a new sub-clause [locale.nonmembers] immediately after the existing 28.3.3.1.6 [locale.statics] as indicated:

    28.3.3.1.? Non-member functions [locale.nonmembers]

    void swap(locale& lhs, locale& rhs) noexcept;
    

    -?- Effects: Exchanges the values of lhs and rhs.