------- Comment #4 from vbraun at physics dot upenn dot edu 2007-04-25 16:51 ------- Super-condensed testcase (gcc 4.1.2):
-------------- snip on ----------------- template<typename T> void f() {} class A { void f() {}; friend void f<int>(); // line 5 }; -------------- snip off ----------------- [EMAIL PROTECTED] test]$ c++4 -Wall -pedantic friendtest.cc friendtest.cc:5: error: variable or field f declared void friendtest.cc:5: error: f is neither function nor member function; cannot be declared friend friendtest.cc:5: error: expected ; before < token The following versions all compile correctly (but do different things): -------------- snip on ----------------- template<typename T> void f() {} class A { void f() {}; friend void ::f<int>(); // Explicitly name scope }; ---------------------------------------- template<typename T> void f() {} class A { friend void f<int>(); // friend before member void f() {}; }; ---------------------------------------- template<typename T> void f() {} class A { void f() {}; template<typename T> friend void f(); // many-to-many friend }; ---------------------------------------- void f() {} class A { void f() {}; friend void f(); // no template }; -------------- snip off ---------------- Something is wrong with the friend lookup after a member of the same name is encountered. After seeing the class member f (either data member or member function), gcc forgets that the template function f is in the current namespace. See also: Discussion for friend lookup rules. http://std.dkuug.dk/jtc1/sc22/wg21/docs/cwg_defects.html#166 According to this, the code should be valid. Bug 17122 is a duplicate, but did not see any activity in 1 year. -- vbraun at physics dot upenn dot edu changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |vbraun at physics dot upenn | |dot edu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30431