This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: (C++) patch to protected member access


>>>>> Mark Mitchell <mark@codesourcery.com> writes:

 > I think the standard can be construed as correct if you don't smash
 > using declarations to the things they refer to.  (As we've discussed
 > privately, G++ does this internally, but that doesn't mean the
 > standard does.)

 > The standard says that using declarations are a synonym -- it doesn't
 > say that there some kind of semantic macro that sucks in all the
 > referred-to functions.  So, I think the program is legal because name
 > look for the call to `f' finds `B::f', which is a public using
 > declaration.

Hmm, that makes sense.

 > So, I think that instead of your patch we should bite the bullet on
 > the handling of using declarations.  It should be relatively easy to,
 > instead of actually inserting the functions in the class, just put a
 > USING_DECL which contains a list of the functions that would have been
 > inserted.

Note that my patch also fixes

  struct A {
  protected:
    int i;
  };

  struct B: public A { };

  struct C: public A {
    void f () {
      B::i = 0;
    }
  };

Here, i is accessible when named in B because it's accessible when named in
A.  Before my patch, g++ was treating B specially in
protected_accessible_p, which is not appropriate.

I suppose we could change it back to check for private or protected access,
but I'd rather leave it for now.

Jason

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]