[jv@smith misc]$ cat -n decl_friend_class.cpp 1 2 #ifdef DD 3 class d; 4 #endif 5 6 class c 7 { 8 friend class d; 9 d* p; 10 }; 11 [jv@smith misc]$ /usr/local/gcc/gcc-4.0.0/bin/g++ -c -W -Wall decl_friend_class.cpp [jv@smith misc]$ /usr/local/gcc/gcc-4.0.1/bin/g++ -c -W -Wall decl_friend_class.cpp decl_friend_class.cpp:9: error: ISO C++ forbids declaration of 'd' with no type decl_friend_class.cpp:9: error: expected ';' before '*' token [jv@smith misc]$ /usr/local/gcc/gcc-4.0.1/bin/g++ -c -W -Wall -fpermissive decl_friend_class.cpp decl_friend_class.cpp:9: warning: ISO C++ forbids declaration of 'd' with no type decl_friend_class.cpp:9: error: expected ';' before '*' token [jv@smith misc]$ /usr/local/gcc/gcc-4.0.1/bin/g++ -c -W -Wall -DDD decl_friend_class.cpp [jv@smith misc]$ icc -c -w2 decl_friend_class.cpp [jv@smith misc]$ The icc here is icc 8.1 The original testcase comes from SystemC 2.0.1, in include/systemc/kernel/sc_module_name.h ( http://www.systemc.org/ ) IANAC++LL. It is not immediately clear to me from the standard whether a friend class decl declares that class, though the description of a friend function decl suggests - to me, anyway - that it might. I would be grateful if anyone could refer me to a discussion of whether or not this is valid C++, acording to current interpretations of the standard. However: I believe that this code is accepted by gcc-2.95, gcc-3.2.x, gcc-3.4.x, gcc-4.0.0 without warning, so if it has been determined to be invalid, it should reeceive a "deprecated" warning and/or require -fpermissive before it ceases to be accepted by gcc. Regards, John. I will test minor release candidates more in future...
The code is in fact invalid. friend should not inject the class at all. The reason why we did not have a deprecated period or allow it with -fpermissive is because we actually got a bug report about accepting this invalid code. Just add the forward declaration.