By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,948 Members | 1,663 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,948 IT Pros & Developers. It's quick & easy.

GNU C: Namespace resolution operator on friend declarations problem

P: n/a
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.
Jul 19 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a

"Alexander Grigoriev" <al***@earthlink.net> wrote in message
news:UO*****************@newsread3.news.pas.earthl ink.net...
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
Jul 19 '05 #2

P: n/a
On Thu, 11 Sep 2003 14:39:48 GMT, "Alexander Grigoriev"
<al***@earthlink.net> 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 believeit'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
Jul 19 '05 #3

P: n/a
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" <to********@hotmail.com> wrote in message
news:dj********************************@4ax.com...
On Thu, 11 Sep 2003 14:39:48 GMT, "Alexander Grigoriev"
<al***@earthlink.net> wrote:
I've got a problem with GNU C++ for ARM, which is used in WindRiver Tornado2.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 semanticambiguity with that.


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

Tom

Jul 19 '05 #4

P: n/a
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" <al***@earthlink.net> wrote in message
news:UO*****************@newsread3.news.pas.earthl ink.net...
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.

Jul 19 '05 #5

P: n/a
On Fri, 12 Sep 2003 02:51:59 GMT, "Alexander Grigoriev"
<al***@earthlink.net> 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
Jul 19 '05 #6

P: n/a
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.

Jul 19 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.