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

            Bug ID: 64063
           Summary: Incorrect "ambiguous template specialization" error
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Keywords: rejects-valid
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org

G++ rejects this explicit instantiation definition as ambiguous:

template<typename T>
struct S
{
  void foo(int) { }
  template<typename U> void foo(U) { }
};

template void S<char>::foo(int);  // XXX


EDG thinks it's OK, clang crashes, and G++ says:


inst.cc:8:15: error: ambiguous template specialization ‘foo<>’ for ‘void
S<char>::foo(int)’
 template void S<char>::foo(int);  // XXX
               ^
inst.cc:4:8: note: candidates are: void S<T>::foo(int) [with T = char]
   void foo(int) { }
        ^
inst.cc:5:29: note:                 template<class U> void S<T>::foo(U) [with U
= U; T = char]
   template<typename U> void foo(U) { }
                             ^


I think EDG is correct and the diagnostic is wrong, because I'm not referring
to any foo<> but rather foo.


Changing the instantiation to be unambiguously a template produces almost the
same error (with foo<> replaced by foo<int>) and that definitely isn't
ambiguous because one candidate isn't even a function template:

template<typename T>
struct S
{
  void foo(int) { }
  template<typename U> void foo(U) { }
};

template void S<char>::foo<int>(int);  // XXX


inst.cc:8:15: error: ambiguous template specialization ‘foo<int>’ for ‘void
S<char>::foo(int)’
 template void S<char>::foo<int>(int);  // XXX
               ^
inst.cc:4:8: note: candidates are: void S<T>::foo(int) [with T = char]
   void foo(int) { }
        ^
inst.cc:5:29: note:                 template<class U> void S<T>::foo(U) [with U
= U; T = char]
   template<typename U> void foo(U) { }
                             ^

Reply via email to