https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63263
Bug ID: 63263 Summary: friend declaration of template specialization of function gets confused when specialization was forward declared Product: gcc Version: 4.7.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: carlo at gcc dot gnu.org The following code snippet should compile, but it doesn't. template<typename T> void f(T&, float&) { T(1); } struct B; template<> void f(B&, float&) { } struct B { friend void f<B>(B&, float&); }; void g() { B b; float n; f(b, n); } The result is: troep.cc: In instantiation of ‘void f(T&, float&) [with T = B]’: troep.cc:22:9: required from here troep.cc:4:3: error: no matching function for call to ‘B::B(int)’ troep.cc:4:3: note: candidates are: troep.cc:14:8: note: B::B() troep.cc:14:8: note: candidate expects 0 arguments, 1 provided troep.cc:14:8: note: B::B(const B&) troep.cc:14:8: note: no known conversion for argument 1 from ‘int’ to ‘const B&’ troep.cc:4: confused by earlier errors, bailing out Preprocessed source stored into /tmp/ccjzbrcd.out file, please attach this to your bugreport. If I either comment out the friend declaration, or move the specialization to after the struct B declaration (so that the friend declaration caused the specialization), then it compiles and works. clang compiles this fine.