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

            Bug ID: 126717
           Summary: GCC accepts duplicate definitions of an explicitly
                    specialized member function template
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: accepts-invalid
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: attackerj1113 at gmail dot com
  Target Milestone: ---

GCC accepts the following code, whereas Clang, MSVC and EDG reject it:

==========================
template<class T>
struct A {
    template<class U>
    int f(U) {
        return 42;
    }
};

template<>
template<class U>
int A<int>::f(U) {
    return 1;
}

template<>
template<class U>
int A<int>::f(U) {
    return 2;
}

//template int A<int>::f<int>(int);
==========================

https://godbolt.org/z/Tshxfvqfd

The two definitions of A<int>::f denote the same entity. This involves an
explicitly specialized member function template of a class template, and the
duplicate definitions should therefore be diagnosed as a redefinition.

Reply via email to