This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: [C++ bug] access control for types
> Anyway, even with the explicit friendship, you get the same errors.
Hi Nathan,
I don't: With 20000210, g++ accepts my code (with the friend
declarations) as posted...
> /* The type and its nested classes are implicitly friends, as
> per core issue 45 (this is a change from the standard). */
[...]
> The above code doesn't quite match the comment. The comment implies a
> bi-directional friendship -- the nested class is a friend of its
> container, and the container is a friend of the nested class.
The text of this issue is available at
http://www.informatik.hu-berlin.de/~loewis/corer8.html#45
(among other places). The proposed resolution reads
# A member class should have access to the members of the enclosing
# class in the same manner as if it had been declared a friend of the
# enclosing class. See paper J16/99-0009 = WG21 N1186.
This doesn't imply biderectional friendship, so I'd say that g++
implements that part correctly. Indeed, is_friend(Berived, Nested)
returns true.
> So, I agree with you that explicit friendship is needed by the
> standard, but it is not needed according to the (intended) behaviour.
> Perhaps a pedwarn is necessary here. It depends on what we mean by
> pedantic. Adherance to the published standard plus any normative
> thingies (I've forgotten the proper name). Or adherence to the
> published standard plus defect reports as they are resolved.
I'd say g++ should consider defect reports according to the likely
resolution. Issue 45 is in drafting state, so it seems that future
corrigendum will most likely support the current implementation.
I didn't know this was an issue, so I earlier took the position that
your code is ill-formed. Now I think it should be accepted. I haven't
analysed this further; the problem appears to be that the protected
access doesn't take this implicit friendship into account. I see that
is_friend(Base, Nested) is being called, which (correctly) returns
false. I haven't found the place where friends get access to protected
members.
Regards,
Martin