Hi,
this is about the anonymous struct extension, but I think submitter is
right that we should accept the testcase (indeed both clang and edg
already do): in the below I propose to simply add a test of
ANON_AGGR_TYPE_P (DECL_CONTEXT (field)). Note that, given the definition
of ANON_AGGR_TYPE_P, should not be necessary to take care explicitly of
anonymous unions: to be safe I'm adding a negative test for those.
Tested x86_64-linux.
Thanks,
Paolo.
/////////////////////////////
/cp
2015-07-08 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/66644
* class.c (check_field_decl): Do not reject multiple initialized
fields in anonymous struct.
/testsuite
2015-07-08 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/66644
* g++.dg/cpp0x/anon-struct1.C: New.
Index: cp/class.c
===================================================================
--- cp/class.c (revision 225556)
+++ cp/class.c (working copy)
@@ -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;
}
Index: testsuite/g++.dg/cpp0x/anon-struct1.C
===================================================================
--- testsuite/g++.dg/cpp0x/anon-struct1.C (revision 0)
+++ testsuite/g++.dg/cpp0x/anon-struct1.C (working copy)
@@ -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];
+ };
+};