Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Sanity Check -- Is this valid C++?

Reply
Thread Tools

Sanity Check -- Is this valid C++?

 
 
Jonathan Pryor
Guest
Posts: n/a
 
      02-15-2006
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

 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      02-15-2006
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
 
Reply With Quote
 
 
 
 
Sumit Rajan
Guest
Posts: n/a
 
      02-15-2006

"Jonathan Pryor" <> wrote in message
news: oups.com...
> 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.
--
Sumit Rajan <>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sanity check on use of dictionaries dopey483@gmail.com Python 1 11-02-2006 03:56 PM
Containers & Iterators sanity check Evan Carew C++ 2 12-29-2005 02:10 AM
Boost sanity check Evan Carew C++ 0 11-04-2004 01:06 AM
Sanity check output streambuf scheme? Fred Ma C++ 9 04-02-2004 10:50 PM
Sanity check - policy routing example on CCO DaveS Cisco 2 02-26-2004 11:05 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57