[Bug c/112972] ambiguity in specification for cast to union types

2023-12-11 Thread stephan.stiller at outlook dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112972

Stephan Stiller  changed:

   What|Removed |Added

 Status|RESOLVED|UNCONFIRMED
 Resolution|INVALID |---

--- Comment #2 from Stephan Stiller  ---
I disagree; the documentation overall is contradictory with respect to whether
reading from a different member with the same type is also considered "type
punning".

Given the example of union datum p, it wouldn't make sense for any compiler to
not produce code with the intended effect for something like the following:
p.height = 3.4;
double d = p.weight;
However, the point is that this is not explicitly documented for the case of
different members having identical types.

For the example from the GCC webpage, if union foo were replaced by union
datum, it would be unclear what the "equivalence" would be. (The choice of
latitute/longitude/height/weight as the designated member of type double
wouldn't matter in practice, but again, this needs to be said explicitly.)

[Bug c/112972] ambiguity in specification for cast to union types

2023-12-11 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112972

Andrew Pinski  changed:

   What|Removed |Added

 Resolution|--- |INVALID
 Status|UNCONFIRMED |RESOLVED

--- Comment #1 from Andrew Pinski  ---
>and this should be stated somewhere in the documentation

Actually it is documented.

https://gcc.gnu.org/onlinedocs/gcc-13.2.0/gcc/Optimize-Options.html#Type-punning

The practice of reading from a different union member than the one most
recently written to (called “type-punning”) is common. Even with
-fstrict-aliasing, type-punning is allowed, provided the memory is accessed
through the union type.