On Wed, Dec 14, 2011 at 05:14:18PM -0500, Jason Merrill wrote: > --- a/gcc/c-family/c-common.c > +++ b/gcc/c-family/c-common.c > @@ -6286,13 +6286,21 @@ handle_transparent_union_attribute (tree *node, tree > name, > > if (TREE_CODE (type) == UNION_TYPE) > { > - /* When IN_PLACE is set, leave the check for FIELDS and MODE to > - the code in finish_struct. */ > + /* Make sure that the first field will work for a transparent union. > + If the type isn't complete yet, leave the check to the code in > + finish_struct. */ > + if (TYPE_SIZE (type)) > + { > + tree first = first_field (type); > + if (first == NULL_TREE > + || TYPE_MODE (type) != DECL_MODE (first)) > + goto ignored; > + }
I'd think it would be nicer to emit the same diagnostic from this spot as we do if handle_transparent_union_attribute is called on an incomplete type and finish_struct is called later. Unfortunately that varies between C and C++ FEs, we'd need a langhook for that, which is perhaps an overkill for such rarely used attribute. So, I'm fine with this patch for the trunk too, though perhaps you want also || first == error_mark_node || DECL_ARTIFICIAL (first) for the condition to catch what finish_struct_1 does for C++? Jakub