https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128657

            Bug ID: 128657
           Summary: std::is_swappable no longer reflects actual
                    swappability
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ykakeyama3014 at gmail dot com
  Target Milestone: ---

Since r16-2273-g178dc3367643 "Constrain std::swap using concepts in C++20", the
std::swap templates in bits/move.h use requires-clauses in C++20, but
<type_traits> still declares them with enable_if return types. This makes
std::is_swappable disagree with whether swap can actually be called.

Repro code is as follows:


#include <concepts>
#include <type_traits>
#include <utility>

namespace ns {

struct S {};

template<std::same_as<S> T>
void swap(T&, T&)
{
}

}  // namespace ns

static_assert(std::is_swappable_v<ns::S>);  // pass

void func(ns::S& a, ns::S& b)
{
  using std::swap;
  swap(a, b);  // error
}


With -std=c++20, the static_assert passes but the swap call is ambiguous. GCC
15 accepts both.

Reply via email to