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

            Bug ID: 97279
           Summary: GCC ignores the operation definition of the template
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tangyixuan at mail dot dlut.edu.cn
  Target Milestone: ---

Hi, gcc selects the overloaded definition operation+() although it is not
declared before.

$ cat s.cpp

#include <iostream>
struct S {
    template <typename T>
    void operator+(T) { std::cout << "1" <<"\n"; }
};
namespace N {
    template <typename T>
    void func(const T value1) { S s; s +(value1); }
}

struct S1 {};
namespace N {
    void operator+(S&, S1) { std::cout << "2" <<"\n"; }
}

int main(int, char**)
{
    S1 s1;
    N::func(s1);
}

$ g++ s.cpp
$ ./a.out
2

$ clang++ s.cpp
$ ./a.out
1

Reply via email to