This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/13935] [3.4/3.5 Regression] Template friend lookup bug
- From: "gdr at integrable-solutions dot net" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 30 Jan 2004 19:23:21 -0000
- Subject: [Bug c++/13935] [3.4/3.5 Regression] Template friend lookup bug
- References: <20040130165003.13935.giovannibajo@libero.it>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Additional Comments From gdr at integrable-solutions dot net 2004-01-30 19:23 -------
Subject: Re: [3.4/3.5 Regression] Template friend lookup bug
"giovannibajo at libero dot it" <gcc-bugzilla@gcc.gnu.org> writes:
| ------- Additional Comments From giovannibajo at libero dot it 2004-01-30 17:58 -------
| Well, when I say:
|
| friend class B;
|
| I'm saying that ::B is a friend of MainClass<> (and ::B is thus predeclared).
| Then, I'm defining MainClass<>::B<>, which is a totally unrelated
| type. I don't see how this could be illegal.
That is the same thing as for
struct foo { };
struct bar {
foo foo;
};
The first 'foo' refers to the outer foo, and the second changes the
meaning of the first. That is ill-formed even though a diagnostic is
not required. If you want to make that valid construct, then you need
to qualify explicitly
struct bar {
::foo foo;
};
See 3.3.6/1
[...]
2) A name N used in a class S shall refer to the same declaration
in its context and when reevaluated in the completed scope of
S. No diagnostic is required for a violation of this rule.
| I think the crucial point is about this:
| template < class TP2 > friend class B;
|
| Does this refer to ::B or to MainClass<>::B<>?
That refers to the second, but then the meaning of the use of the
unqualified name 'B' changes after the class is completed.
| How is the lookup performed, exactly?
On the first friend declaration, one looks into the current class
scope, finds nothing, then looks into the enclosing namespace scope.
One finds ::B. But when MainClass<> is completed, you see that the
meaning of B (as en unqualified name in the scope of MainClass<>) has
changed. So, your program is in error.
-- Gaby
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13935