===================================================================
@@ -3568,7 +3568,8 @@ check_field_decl (tree field,
{
/* `build_class_init_list' does not recognize
non-FIELD_DECLs. */
- if (TREE_CODE (t) == UNION_TYPE && *any_default_members != 0)
+ if (TREE_CODE (t) == UNION_TYPE && *any_default_members != 0
+ && !ANON_AGGR_TYPE_P (DECL_CONTEXT (field)))
error ("multiple fields in union %qT initialized", t);
*any_default_members = 1;
}
===================================================================
@@ -0,0 +1,21 @@
+// PR c++/66644
+// { dg-do compile { target c++11 } }
+// { dg-options "" }
+
+struct testP
+{
+ union U
+ {
+ struct { char a=0, b=0; };
+ char buffer[16];
+ };
+};
+
+struct testN
+{
+ union U
+ {
+ union { char a=0, b=0; }; // { dg-error "multiple fields" }
+ char buffer[16];
+ };
+};