Sanity Check -- Is this valid C++?

Discussion in 'C++' started by Jonathan Pryor, Feb 15, 2006.

  1. 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
    Jonathan Pryor, Feb 15, 2006
    #1
    1. Advertising

  2. 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
    Victor Bazarov, Feb 15, 2006
    #2
    1. Advertising

  3. Jonathan Pryor

    Sumit Rajan Guest

    "Jonathan Pryor" <> wrote in message
    news:...
    > 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 <>
    Sumit Rajan, Feb 15, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Fred Ma
    Replies:
    9
    Views:
    441
    Fred Ma
    Apr 2, 2004
  2. Evan Carew

    Boost sanity check

    Evan Carew, Nov 4, 2004, in forum: C++
    Replies:
    0
    Views:
    333
    Evan Carew
    Nov 4, 2004
  3. Replies:
    1
    Views:
    264
    Fredrik Lundh
    Nov 2, 2006
  4. Evan Carew
    Replies:
    2
    Views:
    340
    Evan Carew
    Dec 29, 2005
  5. Ben Pope

    Sanity Check

    Ben Pope, Feb 17, 2006, in forum: C++
    Replies:
    4
    Views:
    535
    Ben Pope
    Feb 17, 2006
Loading...

Share This Page