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

--- Comment #2 from Laszlo Ersek (RH) <lersek at redhat dot com> ---
(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, what pointer casts trickery with
> unions it did.

I disagree, and in my opinion, the standard disagrees too.

> You can access a union type as the type of any of its members.  But a
> double is not a union type.

I didn't claim it was.

The standard writes,

    An object [the double] shall have its stored value accessed only by
    an lvalue expression that has one of the following types:

    [...]

    - a [...] union type that includes [a type compatible with the
      effective type of the [double] object] among its members

It says we can access a "double" through a union which has a "double"
member.

  union u {
    int i;
    double d1;
  };

  double d2;

The expression (*(union u *)&d2) is an lvalue expression that has a
union type that includes a double among its members.

To me this seems to follow from the letter of the standard. If my
interpretation is incorrect, or the standard is unclear or incorrect,
please show that. Thanks.

Reply via email to