[C++ bug] access control for types

Nathan Sidwell nathan@acm.org
Fri Feb 11 15:13:00 GMT 2000


Martin,
You've fixed the problem by explicitly making Derived::Nested a friend
of Derived. I originally had that, but I've always considered it
awkward that nested classes weren't automatically friends of the
containing class.

Anyway, even with the explicit friendship, you get the same errors.

In examining Jason's patch, I found this,

friend.c:102 (is_friend)
    /* It's a type.  */
    {
      /* The type and its nested classes are implicitly friends, as
         per core issue 45 (this is a change from the standard).  */
      for (context = supplicant;
           context && TYPE_P (context);
           context = TYPE_CONTEXT (context))
        if (type == context)
          return 1;

which makes nested friends.

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. However,
the code only returns true when SUPPLICANT is the nested class and TYPE
is its container. I'm not familiar with the text of core issue 45, so
don't know which is correct -- IMHO the code is right, because
this bidirectional friendship seems weird -- Jason?

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.

nathan
-- 
Dr Nathan Sidwell :: Computer Science Department :: Bristol University
Never hand someone a gun unless you are sure where they will point it
nathan@acm.org  http://www.cs.bris.ac.uk/~nathan/  nathan@cs.bris.ac.uk


More information about the Gcc-bugs mailing list