http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54058
Bug #: 54058 Summary: Injected friend functions are not considered when using contextual type info to take a function address Classification: Unclassified Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: andy.m.j...@gmail.com Created attachment 27851 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=27851 Compiler output When attempting to take a function address where contextual type info is needed, injected friend functions are not properly considered. Here is the source file: template<typename Derived> struct Injector { friend Derived const f(Derived const &) { return Derived(); } }; struct A : Injector<A> {}; struct B : Injector<B> {}; int main() { A const (*fp)(A const &) = &f; (void)fp; } The error given is particularly confusing: g++ reports no matching function, but then proceeds to give a list of candidates that includes an exact match! test.cpp: In function ‘int main()’: test.cpp:11:31: error: no matches converting function ‘f’ to type ‘const struct A (*)(const struct A&)’ test.cpp:3:24: error: candidates are: const A f(const A&) test.cpp:3:24: error: const B f(const B&) The full output of "g++ -v -save-temps -Wall -Wextra test.cpp" is attached. Found with g++ 4.5.2.