[Bug c/65892] gcc fails to implement N685 aliasing of union members

pinskia at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Sun Apr 26 17:50:00 GMT 2015


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65892

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Martin Sebor from comment #4)
> Thanks for the pointer!  I had looked for a related bug report but couldn't
> find it.
> 
> There's an important difference between the test cases in pr14319 and the
> one here that's easy to overlook.  The rule only applies to structs defined
> in unions, not those defined at file scope and only used to declare union
> members, and to translation units in which the union definition is visible. 


No that is not the rule.  If I read the section:
    [#5] One special guarantee is made in order to simplify the use of unions:
if a union contains several structures that share a common initial sequence
(see
below), and if the union object currently contains one of these structures, it
is permitted to inspect the common initial part of any of them anywhere that a
declaration of the complete type of the union is visible. Two structures share
a
common initial sequence if corresponding members have compatible types (and,
for
bit-fields, the same widths) for a sequence of one or more initial members.
--- CUT ----
I don't see anywhere the standard says about where the struct is defined in the
statement above.



More information about the Gcc-bugs mailing list