<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On May 28, 2010, at 10:46 AM, Abramo Bagnara wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>Il 28/05/2010 19:25, John McCall ha scritto:<br><blockquote type="cite">On May 28, 2010, at 9:00 AM, Abramo Bagnara wrote:<br></blockquote><blockquote type="cite"><blockquote type="cite">I might imagine this is done<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">for access checking, but as I'd guess that access checking is done<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">traversing and checking *all* the nesting records (also anonymous ones)<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">the union fields would be unaccessible from outside class S also if<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">correctly marked as public.<br></blockquote></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Your guess is wrong;  we assume that the decl's access specifier correctly<br></blockquote><blockquote type="cite">describes the access of the member when considered as a member of its<br></blockquote><blockquote type="cite">declaring class.  There is no value in remembering the access of the decl<br></blockquote><blockquote type="cite">within the anonymous union, first, because it is impossible to access<br></blockquote><blockquote type="cite">anything from the context of the anonymous union (as opposed to<br></blockquote><blockquote type="cite">from its enclosing context) after it is parsed, and second, because<br></blockquote><blockquote type="cite">(as you've rightly observed) that access is always public.<br></blockquote><br>I'm not sure to understand the difference you see between<br><br>class s {<br>  struct {<br>    int a;<br>    int b;<br>  };<br>};<br><br>and<br><br>class q {<br>  struct {<br>    int a;<br>    int b;<br>  } c;<br>};<br><br>and why you treat the former as a special case, but that apart it's not<br>a problem in either way once there is the possibility to know access<br>specifier written in source.<br></div></blockquote><div><br></div>Because it is a special case.  The first case is an anonymous union;  the</div><div>second case is just a field of anonymous type.  In the first case, 'a' and 'b'</div><div>are visible as members of 's';  in the second case they are not.</div><div><br></div><div>This is C++ [class.union]p4:</div><div>  A union for which objects or pointers are declared is not an anonymous union.</div><div><br><blockquote type="cite"><div><blockquote type="cite">Is there a value to remembering the original access specifier, i.e. public,<br></blockquote><blockquote type="cite">that I'm not seeing?  I would much prefer not to change the current behavior,<br></blockquote><blockquote type="cite">but we could certainly provide a method that reports the "direct" access<br></blockquote><blockquote type="cite">specifier, i.e. public if the DC is an anonymous struct or union.<br></blockquote><br>The value is for pretty printer like applications and for source<br>checkers. However to add an AccessSpecifierAsWritten flag inside the<br>decl is not the ideal solution, it can't represent something like this:<br><br>class s {<br>private:<br>  int a;<br>};<br><br>(undistiguishable from class s { int a; })<br><br>or<br><br>class s {<br>public:<br>private:<br>  int a;<br>};<br><br>To represent correctly the above we might decide to have a node for<br>access specifiers at the same level of other decls.<font class="Apple-style-span" color="#000000"><font class="Apple-style-span" color="#144FAE"><br></font></font></div></blockquote><br></div><div>Yes, I've been wanting something like this for some time.</div><div><br></div><div>John.</div></body></html>