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

Nikola Smiljanic popizdeh at gmail.com
Wed Aug 15 08:56:26 PDT 2012


Hi John,

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?



More information about the cfe-commits mailing list