GNU C: Namespace resolution operator on friend declarations problem

Discussion in 'C++' started by Alexander Grigoriev, Sep 11, 2003.

  1. I've got a problem with GNU C++ for ARM, which is used in WindRiver Tornado
    2.11 environment.

    I tried the following construct:

    void foo();

    namespace N
    {

    class C
    {
    friend void ::foo();
    };

    }

    GCC does not accept namespace resolution in the friend function declaration.
    MS Visual C compiler is happy with it, though.

    ANSI C++ standard allows fully qualified name in friend declaration when
    referring to a member function of another class, but doesn't say anything
    about referring to a nonmember function from another namespace. I believe
    it's just oversight, because there doesn't seem any syntactic and semantic
    ambiguity with that.
    Alexander Grigoriev, Sep 11, 2003
    #1
    1. Advertising

  2. "Alexander Grigoriev" <> wrote in message
    news:UO%7b.7626$...
    > I've got a problem with GNU C++ for ARM, which is used in WindRiver

    Tornado
    > 2.11 environment.
    >
    > I tried the following construct:
    >
    > void foo();
    >
    > namespace N
    > {
    >
    > class C
    > {
    > friend void ::foo();
    > };
    >
    > }
    >
    > GCC does not accept namespace resolution in the friend function

    declaration.
    > MS Visual C compiler is happy with it, though.
    >

    I would put my trust with MS VC++ compiler here..even though can't quote
    from the standard right away ;-).

    --
    J.Schafer
    Josephine Schafer, Sep 11, 2003
    #2
    1. Advertising

  3. Alexander Grigoriev

    tom_usenet Guest

    On Thu, 11 Sep 2003 14:39:48 GMT, "Alexander Grigoriev"
    <> wrote:

    >I've got a problem with GNU C++ for ARM, which is used in WindRiver Tornado
    >2.11 environment.
    >
    >I tried the following construct:
    >
    >void foo();
    >
    >namespace N
    >{
    >
    >class C
    >{
    >friend void ::foo();
    >};
    >
    >}
    >
    >GCC does not accept namespace resolution in the friend function declaration.
    >MS Visual C compiler is happy with it, though.
    >
    >ANSI C++ standard allows fully qualified name in friend declaration when
    >referring to a member function of another class, but doesn't say anything
    >about referring to a nonmember function from another namespace.


    It does - a friend function declaration can use a qualified name.

    I believe
    >it's just oversight, because there doesn't seem any syntactic and semantic
    >ambiguity with that.


    The code is perfectly standard. You must have an old version of gcc,
    since 3.2 compiles it fine.

    Tom
    tom_usenet, Sep 11, 2003
    #3
  4. I'd suspect the compiler in question has relied too much on the standard
    text. Since the standard doesn't mention friends from other namespaces (only
    from other classes), the developpers decided that it's not allowed. I'd
    consider such omission in the standard text a defect.

    "tom_usenet" <> wrote in message
    news:...
    > On Thu, 11 Sep 2003 14:39:48 GMT, "Alexander Grigoriev"
    > <> wrote:
    >
    > >I've got a problem with GNU C++ for ARM, which is used in WindRiver

    Tornado
    > >2.11 environment.
    > >
    > >I tried the following construct:
    > >
    > >void foo();
    > >
    > >namespace N
    > >{
    > >
    > >class C
    > >{
    > >friend void ::foo();
    > >};
    > >
    > >}
    > >
    > >GCC does not accept namespace resolution in the friend function

    declaration.
    > >MS Visual C compiler is happy with it, though.
    > >
    > >ANSI C++ standard allows fully qualified name in friend declaration when
    > >referring to a member function of another class, but doesn't say anything
    > >about referring to a nonmember function from another namespace.

    >
    > It does - a friend function declaration can use a qualified name.
    >
    > I believe
    > >it's just oversight, because there doesn't seem any syntactic and

    semantic
    > >ambiguity with that.

    >
    > The code is perfectly standard. You must have an old version of gcc,
    > since 3.2 compiles it fine.
    >
    > Tom
    Alexander Grigoriev, Sep 12, 2003
    #4
  5. Alexander Grigoriev

    Yan Meunier Guest

    I also use GNU C++ for VxWorks on a pentium architect. If your using GCC
    2.7.2, as I am, I do believe this version does not completely support
    namespaces.

    "Alexander Grigoriev" <> wrote in message
    news:UO%7b.7626$...
    > I've got a problem with GNU C++ for ARM, which is used in WindRiver

    Tornado
    > 2.11 environment.
    >
    > I tried the following construct:
    >
    > void foo();
    >
    > namespace N
    > {
    >
    > class C
    > {
    > friend void ::foo();
    > };
    >
    > }
    >
    > GCC does not accept namespace resolution in the friend function

    declaration.
    > MS Visual C compiler is happy with it, though.
    >
    > ANSI C++ standard allows fully qualified name in friend declaration when
    > referring to a member function of another class, but doesn't say anything
    > about referring to a nonmember function from another namespace. I believe
    > it's just oversight, because there doesn't seem any syntactic and semantic
    > ambiguity with that.
    >
    >
    Yan Meunier, Sep 12, 2003
    #5
  6. Alexander Grigoriev

    tom_usenet Guest

    On Fri, 12 Sep 2003 02:51:59 GMT, "Alexander Grigoriev"
    <> wrote:

    >I'd suspect the compiler in question has relied too much on the standard
    >text. Since the standard doesn't mention friends from other namespaces (only
    >from other classes), the developpers decided that it's not allowed. I'd
    >consider such omission in the standard text a defect.


    You'll have to explain why you think that the standard makes this
    illegal:

    namespace A
    {
    void foo();
    }

    class Bar
    {
    friend void A::foo();
    };

    8.3/1 explicitly allows a friend function declaration to name a
    qualified-id (like A::foo).

    Tom
    tom_usenet, Sep 12, 2003
    #6
  7. Alexander Grigoriev wrote:

    > Now I see: "or the declaration of a friend function that is a member of
    > another class or namespace"
    >


    Please don't top-post. Read section 5 of the FAQ for posting guidelines.

    http://www.parashift.com/c -faq-lite/

    -Kevin
    --
    My email address is valid, but changes periodically.
    To contact me please use the address from a recent posting.
    Kevin Goodsell, Sep 12, 2003
    #7
    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. Peter

    1 day gnu, whole life gnu?

    Peter, Jan 10, 2005, in forum: Java
    Replies:
    3
    Views:
    337
    John C. Bollinger
    Jan 10, 2005
  2. Peter
    Replies:
    17
    Views:
    603
    Chris Smith
    Jan 13, 2005
  3. Tim Partridge
    Replies:
    1
    Views:
    708
    Sumit Rajan
    Jun 2, 2004
  4. Markus Elfring
    Replies:
    2
    Views:
    366
    Markus Elfring
    Feb 23, 2005
  5. dwaach
    Replies:
    1
    Views:
    393
    Victor Bazarov
    Jul 6, 2006
Loading...

Share This Page