This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: g++: 'protected' member function cannot be declared friend
Matt Austern <austern@apple.com> writes:
| On Jan 31, 2005, at 1:12 PM, Matt Austern wrote:
|
| > On Jan 31, 2005, at 1:05 PM, Fariborz Jahanian wrote:
| >
| >>
| >> g++ issues a diagnostic on this test case.
| >> Section 11.4 does not address this issue, but I think that this is
| >> a g++ bug. The
| >> fact that a member function itself is 'protected' should not
| >> prevent it from accessing members of other
| >> classes where it is declared as 'friend'.
| >>
| >>
| >> % cat protected.C
| >> class FOO {
| >> protected:
| >> void Push();
| >> };
| >>
| >> class S {
| >> friend void FOO::Push();
| >> };
| >
| > The problem is the other way around. FOO::Push() is allowed to
| > access private members of classes that declare it to be a friend,
| > but nobody said that class S was allowed to access FOO's private or
| > protected members. This code is illegal.
|
| Oh, and I should mention: the place where this is addressed is 11.4/7:
| "A name nominated by a friend declaration shall be accessible in the
| scope of the class containing the friend declaration". This is an
| error because the name FOO::Push is not accessible in the scope of S.
Isn't this DR #209 ?
http://www.open-std.org/JTC1/SC22/WG21/docs/cwg_closed.html#209
(there must be some humour to the rationale ;-))
-- Gaby