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

            Bug ID: 118365
           Summary: try to define an overloaded function template for a
                    namespace, without having first declared it in that
                    namespace
           Product: gcc
           Version: 14.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ing.russomauro at gmail dot com
  Target Milestone: ---

This bug comes from a wrong implementation of the swap idiom, where I was
trying to define an overload of std::swap.

The code is correctly rejected by clang and MVSC, it uses concepts but I guess
simpler cases may be constructed:


https://godbolt.org/z/TvqK7Kv4z


#include <algorithm>
#include <iostream>
#include <utility>

template<class T>
concept C = requires (T a){a.x;};

template<C T>
void std::swap(T& lhs, T& rhs) {
    std::cout << "overloaded swap\n";
}

struct S{
    int x;
};

int main(){
    S a, b;
    std::swap(a,b);
}

Reply via email to