Sanity Check -- Is this valid C++?

J

Jonathan Pryor

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

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.

Any ideas?

Thanks,
- Jon
 
V

Victor Bazarov

Jonathan said:
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
 
S

Sumit Rajan

Jonathan Pryor said:
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

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.

Any ideas?


Compiled it with VC++8.0 and with Comeau C++ 4.3.3. No problems encountered.

Regards,
Sumit.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top