===================================================================
@@ -3623,7 +3623,11 @@ 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
+ /* As a GNU extension initializing in C++11 multiple fields
+ of an anonymous struct living inside a union is fine. */
+ && !(TREE_CODE (DECL_CONTEXT (field)) == RECORD_TYPE
+ && ANON_AGGR_TYPE_P (DECL_CONTEXT (field))))
error ("multiple fields in union %qT initialized", t);
*any_default_members = 1;
}
===================================================================
@@ -0,0 +1,30 @@
+// PR c++/66644
+// { dg-do compile { target c++11 } }
+// { dg-options "-Wno-pedantic" }
+
+struct test1
+{
+ union
+ {
+ struct { char a=0, b=0; };
+ char buffer[16];
+ };
+};
+
+struct test2
+{
+ union
+ {
+ struct { char a=0, b; };
+ char buffer[16];
+ };
+};
+
+struct test3
+{
+ union
+ {
+ struct { char a, b; } test2{0,0};
+ char buffer[16];
+ };
+};