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

--- Comment #3 from Martin Sebor <msebor at gcc dot gnu.org> ---
Is your concern with mentioning it that it describes the implementation?

Let's see how that works in the full text:

  A cast to union type looks similar to other casts, except that the type
specified is a union type.  You can specify the type either with the union
keyword or with a typedef name that refers to a union.  Unlike a compound
literal, a cast to a union yields an rvalue like standard casts do.  See
Compound Literals. 

This is missing a description of the value of the result of the cast.  All
that's left after the removal of the mention of compound literals is that it's
an rvalue.  (The cross-reference to compound literals then doesn't make much
sense.)

I think it's important to describe what the value of the cast is in the text,
and not just by relying on examples.  The best way that I can think of is by
saying it's an [rvalue of a] compound literal.  That's fully specified in the
standard and it also is what GCC creates internally: a compound literal whose
member that corresponds to the operand is initialized the with the value of the
operand.

  A cast to union type looks similar to other casts, except that the type
specified is a union type.  You can specify the type either with the union
keyword or with a typedef name that refers to a union.  A cast to a union
actually creates a compound literal with the member whose type matches the type
of the operand of the cast initialized with the value of the operand.  Unlike a
compound literal, however, a cast to a union yields an rvalue like standard
casts do.  See Compound Literals.

Adding another example might help clarify this.  Given:

  union foo { int i; double d; };
  int x;
  double y;

  union foo a;

the following

  a = (union foo)x;

is a shorthand equivalent of

  a = (union foo){ .i = x };

(It might be worth also showing an example where the cast doesn't work, i.e.,
when there is no matching type.)

I realize this may not resolve your concern about describing the implementation
but (IIUC) I think it accurately describes the feature.

Reply via email to