GNU C: Namespace resolution operator on friend declarations problem

  • Thread starter Alexander Grigoriev
  • Start date
A

Alexander Grigoriev

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.
 
J

Josephine Schafer

Alexander Grigoriev said:
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 ;-).
 
T

tom_usenet

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
 
A

Alexander Grigoriev

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.
 
Y

Yan Meunier

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.
 
T

tom_usenet

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
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top