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

--- Comment #4 from Alexander Monakov <amonakov at gcc dot gnu.org> ---
My concern is that the cast does not "create a compound literal": what it
creates is an object, more specifically, an unnamed temporary object in
automatic storage with unspecified lifetime [1].  A compound literal in
function scope similarly creates an unnamed object.

Likewise, the "result" of a cast-to-union is that temporary object, taken as
rvalue.

So to explain it well to users, the documentation would have to say something
like:

  A cast to a union creates a temporary object of the given union type,
initialized via a member matching the type of the operand, and taken as rvalue
(unlike a compound literal, which yields an lvalue).

[1] gcc doesn't seem to emit any gimple clobber statements for such casts, so
effectively the lifetime is "entire function scope", but that is likely not
intentional

Reply via email to