https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90167
Segher Boessenkool changed:
What|Removed |Added
Status|UNCONFIRMED |RESOLVED
CC|
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90167
--- Comment #2 from Laszlo Ersek (RH) ---
(In reply to Segher Boessenkool from comment #1)
> The code accesses d, of type double, as an int. That is not a
> compatible type.
Agreed; I didn't claim it was.
> It does not matter how it got there,
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90167
--- Comment #3 from Segher Boessenkool ---
But you are not accessing as the union type. You do the access with the
type of one of its members. And that is UB.
The part of the standard you quote is about things like
union a_union f(double *p)
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90167
--- Comment #4 from Laszlo Ersek (RH) ---
So one way to define the behavior for the original example (from the gcc docs)
would be:
int f(void) {
double d = 3.0;
union a_union u = *(union a_union *)&d;
return u.i;
}
Thanks.