[cfe-dev] Access specifiers and anonymous unions

John McCall rjmccall at apple.com
Fri May 28 10:25:48 PDT 2010


On May 28, 2010, at 9:00 AM, Abramo Bagnara wrote:
> 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.

Your guess is wrong;  we assume that the decl's access specifier correctly
describes the access of the member when considered as a member of its
declaring class.  There is no value in remembering the access of the decl
within the anonymous union, first, because it is impossible to access
anything from the context of the anonymous union (as opposed to
from its enclosing context) after it is parsed, and second, because
(as you've rightly observed) that access is always public.

Is there a value to remembering the original access specifier, i.e. public,
that I'm not seeing?  I would much prefer not to change the current behavior,
but we could certainly provide a method that reports the "direct" access
specifier, i.e. public if the DC is an anonymous struct or union.

John.



More information about the cfe-dev mailing list