Fails on: gcc (GCC) 3.3.4 (Mandrakelinux 10.1 3.3.4-2mdk) Linux 2.6.8.1-12mdk #1 i686 Athlon XP GNU/Linux and g++ (GCC) 3.4.0 SunOS 5.9 Generic_112233-12 sun4u sparc SUNW,UltraAX-i2 The following fails to compile: template<class T> class Foo { // The "friend" declaration below causes fialure with // error: using template type parameter `T' after `class' friend class T; }; class Bar { }; int main(int, char**) { Foo<Bar> foo; return 0; }
I don't think this is valid C++ (at least C++98).
Template parameters can't be used in friend declarations (nor in any elaborated type specifier construct).
Mea Culpa. It was supported by the other compilers I use (MS and Sun), and it seemed like such an obvious thing to want to do, and I didn't think anyone would want explicitly to exclude it, so I didn't check the standard. I'm *very* sorry to have wasted your time. FWIW, I discovered a workaround at http://www.byte.com/documents/s=9162/cujexp0312wilson2/
*** Bug 30390 has been marked as a duplicate of this bug. ***
*** Bug 36601 has been marked as a duplicate of this bug. ***
C++0x has changed the rules slightly and allows: template<class T> class Foo { friend T; }; But GCC does not implement this new rule yet. See 47721. *** This bug has been marked as a duplicate of bug 47721 ***