Jonathan Pryor wrote:
> I'm in need of a sanity check: is the following code valid C++?
>
> namespace foo {
> class NamespaceClass {
> };
> }
>
> using namespace foo;
>
> class Bug_GlobalFriendDeclaresNamespaceClass {
> friend class NamespaceClass;
> };
>
> class UseNamespaceClass {
> public:
> NamespaceClass* GetFoo ();
> friend class NamespaceClass;
> };
>
> int main ()
> {
> }
>
> This compiles for me under GCC 3.3.3 (Linux), GCC 3.4.4 (cygwin), GCC
> 4.0.0 20041026 (Apple build 4061 on a PPC Mac).
>
> This doesn't compile for me under GCC 4.0.1 (Apple build 5250 on an
> intel mac). I suspect a compiler bug, but I'd like to make sure the
> code itself isn't faulty before blaming the compiler. GCC complains
> with the error:
>
> friend.cpp:14: error: ISO C++ forbids declaration of 'NamespaceClass'
> with no type
> friend.cpp:14: error: expected ';' before '*' token
And which line is 14?
> It seems that the friend declaration within
> Bug_GlobalFriendDeclaresNamespaceClass introduces a new NamespaceClass
> declaration (presumably at the global scope) which screws up the
> UseNamespaceClass use of NamespaceClass.
Sounds plausible.
> Any ideas?
The simplest way to check with yet another compiler is to go to Comeau
Computing web site:
http://www.comeaucomputing.com/tryitout/ and compile
your code there. I did. It compiled. GCC project has its own web site
and its own forums, perhaps you should consider posting there.
V
--
Please remove capital As from my address when replying by mail