===================================================================
@@ -6181,7 +6181,10 @@ finish_struct_1 (tree t)
tree field = first_field (t);
if (field == NULL_TREE || error_operand_p (field))
{
- error ("type transparent class %qT does not have any fields", t);
+ if (TREE_CODE (t) == UNION_TYPE)
+ error ("type transparent union %qT does not have any fields", t);
+ else
+ error ("type transparent class %qT does not have any fields", t);
TYPE_TRANSPARENT_AGGR (t) = 0;
}
else if (DECL_ARTIFICIAL (field))
@@ -6195,6 +6198,14 @@ finish_struct_1 (tree t)
}
TYPE_TRANSPARENT_AGGR (t) = 0;
}
+ else if (TYPE_MODE (t) != DECL_MODE (field))
+ {
+ if (TREE_CODE (t) == UNION_TYPE)
+ error ("type transparent union %qT cannot be made transparent", t);
+ else
+ error ("type transparent class %qT cannot be made transparent", t);
+ TYPE_TRANSPARENT_AGGR (t) = 0;
+ }
}
}
===================================================================
@@ -0,0 +1,5 @@
+// PR c++/53761
+
+typedef union { // { dg-error "transparent union" }
+ double x;
+} __attribute__(( __transparent_union__ )) example_t;