(C++) patch to protected member access
Jason Merrill
jason@cygnus.com
Tue Feb 29 14:44:00 GMT 2000
>>>>> Mark Mitchell <mark@codesourcery.com> writes:
>>>>> "Jason" == Jason Merrill <jason@cygnus.com> writes:
Jason> Note that my patch also fixes
Jason> struct A { protected: int i; };
Jason> struct B: public A { };
Jason> struct C: public A { void f () { B::i = 0; } };
Jason> Here, i is accessible when named in B because it's
Jason> accessible when named in A. Before my patch, g++ was
Jason> treating B specially in protected_accessible_p, which is
Jason> not appropriate.
>>> I assume you meant `C : public B'?
Jason> Nope, I meant what I wrote. It's an odd thing to do, but I
Jason> believe well-formed.
> I'll believe you. But, it seems to me that, conceptually, this ought
> to fall under the "you can't use protected things unless you're part
> of the object yourself" rule. That code can't say:
> B b;
> b.i = 3;
> because `i' is protected in `B' and `b' is not a `C' object. So, it
> seems odd to say that `B::i' is legal.
It's legal because B::i means this->B::i, and *this is a 'C' object. The
explicit scope only affects name lookup, which finds A::i, which is
accessed through this.
It used to be that 'B::i' meant something like '((B*) this)->i', but the
committe has abandoned that. I don't really agree, but there it is.
Jason
More information about the Gcc-patches
mailing list