[Bug c++/126717] New: GCC accepts duplicate definitions of an explicitly specialized member function template

attackerj1113 at gmail dot com via Gcc-bugs <[email protected]>
Newsgroups gmane.comp.gcc.bugs
Message-ID <[email protected]/bugzilla/>
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.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.