[Bug c/65892] gcc fails to implement N685 aliasing of union members
aph at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Mon Apr 30 16:17:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65892
--- Comment #45 from Andrew Haley <aph at gcc dot gnu.org> ---
(In reply to Davin McCall from comment #44)
> > Well, perhaps not, but this is the language specification.
>
> The "one special guarantee" clause appears in the section describing union
> member access via the "." or "->" operators, implying that it only applies
> to the access of union members via the union.
I don't believe that's what is intended, or that you can make such a
conclusion based on the section in which the rule appears. It applies
to other accesses too, as is (somewhat) made clear by the rationale in
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n685.htm:
The proposed solution is to require that a union declaration be visible
if aliases through a common initial sequence (like the above) are possible.
Therefore the following TU provides this kind of aliasing if desired:
union utag {
struct tag1 { int m1; double d2; } st1;
struct tag2 { int m1; char c2; } st2;
};
int similar_func(struct tag1 *pst2, struct tag2 *pst3) {
pst2->m1 = 2;
pst3->m1 = 0; /* might be an alias for pst2->m1 */
return pst2->m1;
}
I know this is non-normative and not even in the standard, but it does
explain what was intended.
More information about the Gcc-bugs
mailing list