[cfe-commits] protected anonymous union member not visible in derived class

John McCall rjmccall at apple.com
Wed Aug 15 10:32:48 PDT 2012


On Aug 15, 2012, at 8:56 AM, Nikola Smiljanic wrote:
> I'm investigating http://llvm.org/bugs/show_bug.cgi?id=12788 and would
> like you to comment on my findings. The issue seems to be that
> accessing a member of an anonymous struct/union is not considered an
> instance context (base object type is null). Due to this, the
> class.protected check is executed and fails when the access is
> qualified (A::j) because NamingClass is not equal to ECRecord. Here's
> some code that explains this in more detail:
> 
> class A {
> protected:
>  int i;
> 
>  struct  {
>    int j;
>  };
> };
> 
> class B : public A {
>  friend void fr(B*);
>  void mem();
> };
> 
> void fr(B* b) {
>  // instance contexts, class.protected is not checked
>  b->i = 0;
>  b->A::i = 0;
>  b->j = 0;
>  b->A::j = 0;
> 
>  // these two are not instance contexts, class.protected is checked
> and works OK because NamingClass == ECRecord
>  &B::i;
>  &B::j;
> }
> 
> void B::mem() {
>  // instance contexts, same as above
>  i = 0;
>  A::i = 0;
> 
>  // NOT INSTANCE CONTEXTS???
>  j = 0;
>  A::j = 0;
> }
> 
> I'm under the impression that the last two assignments are both
> instance contexts? The 'j = 0' example seems to be working by chance,
> since NamingClass equals ECRecord in this case. Should we set the base
> type object for these two inside
> BuildAnonymousStructUnionMemberReference so that whole class.protected
> rule is not checked or have I misunderstood something here?

I think you have the right basic idea.  It looks like the instance context is only
not being set for an implicit access.  If you pass down the LookupResult
(with an assertion that it's always a single result) you can also resolve
the FIXME at line 757 about using the real found-decl result.

John.



More information about the cfe-commits mailing list