A valid friend declaration of a function template from a different namespce results in the following error message: friend.cpp:12: `void A::f(B::C*)' should have been declared inside `A' This appears to be a known problem (it is described here: http://www.cuj.com/experts/2101/sutter.htm), but I couldn't find a specific bug report. Release: gcc version 3.2 (mingw special 20020817-1) Environment: Reading specs from d:/opt/mingw/bin/../lib/gcc-lib/mingw32/3.2/specs Configured with: ../gcc/configure --with-gcc --with-gnu-ld --with-gnu-as --host= mingw32 --target=mingw32 --prefix=/mingw --enable-threads --disable-nls --enable -languages=f77,c++,objc,ada --disable-win32-registry --disable-shared Thread model: win32 gcc version 3.2 (mingw special 20020817-1) How-To-Repeat: Save the following program in file 'friend.cpp': namespace A { template <typename T> void f(T * t) { delete t; } } namespace B { class C { private: friend void A::f<>(C *); ~C() {} }; } int main() { B::C * c = new B::C; A::f(c); } Compile with g++ friend.cpp.
Fix: I tried some alternative syntaxes (e.g. by explicitly providing the friend function template argument) without success. The only workaround is to make the required members public.
State-Changed-From-To: open->analyzed State-Changed-Why: Confirmed.
*** This bug has been marked as a duplicate of 8355 ***