[cfe-dev] Access specifiers and anonymous unions

Abramo Bagnara abramo.bagnara at gmail.com
Fri May 28 09:00:01 PDT 2010


class S {
  union {
    int a;
    double b;
  };
};

I've just verified that in the example above clang changes the access
specifier of the two fields of anonymous union to inherit the access
specificier of anonymous union.

Apart that this is contrary to 9.5p3 "An anonymous union shall not have
private or protected members (clause 11)" I might imagine this is done
for access checking, but as I'd guess that access checking is done
traversing and checking *all* the nesting records (also anonymous ones)
the union fields would be unaccessible from outside class S also if
correctly marked as public.

Why this is done? Is it a bug?







More information about the cfe-dev mailing list