[Bug c++/19403] [4.0 Regression] name lookup is broken with friends

gdr at integrable-solutions dot net gcc-bugzilla@gcc.gnu.org
Fri Jan 14 16:07:00 GMT 2005


------- Additional Comments From gdr at integrable-solutions dot net  2005-01-14 16:06 -------
Subject: Re:  [4.0 Regression] name lookup is broken with friends

"Woebbeking at web dot de" <gcc-bugzilla@gcc.gnu.org> writes:

| Subject: Re:  [4.0 Regression] name lookup is broken with friends
| 
| On Thursday 13 January 2005 15:52, lerdsuwa at gcc dot gnu dot org wrote:
| >
| > > So B's ctor uses the global A without the friend declaration and with the
| > > friend declaration the local injected A? Sometimes the holy standard
| > > confuses me a bit.
| >
| > No. With or without friend declaration, the B's ctor should always pick
| > the global A.  This is one weird rule in C++ standard.
| 
| Now I'm even more confused than before. Who is right, Gaby or lerdsuwa?

lerdsuwa is right on all points.  Gaby is right on the friend
declaration and wrong the fact that the code should not compile.
Both lerdsuwa and Gaby agree on what the friend declaration does.

The program would compile (as it does in previous versions) but it
will not have the same semantics as with previous GCC.  The previous
behaviour was wrong in the sense that GCC picked the wrong "A".
When lerdsuwa's patch is applied, your program will be accpeted, but
it will not do what you thought it would do.


As a tangential note, sometime ago, I requested that a
template-parameter be allowed to be a friend (currently 
forbidden). As a result of that reuest, Mike Miller proposed a wording
to amend the current rules and we will have the new friend syntax

       friend T;

where "T" can be any type-name -- not just an elaborated specifier..  
At the moment there is a debate whether that friend-declaration should
introduce a new name (current friend-declaration semantics) or just
refer to an existing declaration (with error if none exists).
John Spicer and I favour the latter semantics.  If that semantics get
adopted, you could leave out the "class" from your friend-declaration
and the semantics would be such that in all cases the compiler will
pick ::A.  Which I believe is the least surprising behaviour.

This proposal had been discussed at several time by both Core and
Evolution groups; and Mike already wrote formal standardese for that.
My hope is that the next meeting would promote that formal
specification to "higher" level, either in the working paper or close
to. But I guess that does not help you much, now.

-- Gaby


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19403



More information about the Gcc-bugs mailing list