Hi,

submitter and Manuel analyzed this a while ago and came to the conclusion - which I think is still valid vs the current working draft - that strictly speaking this kind of code violates [dcl.dcl], thus a pedwarn seems more suited than a plain warning. The below one-liner, suggested by Manuel at the time, passes testing on x86_64-linux together with my testsuite changes.

Thanks,

Paolo.

//////////////////////

/cp
2017-06-16  Manuel Lopez-Ibanez  <m...@gcc.gnu.org>
            Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/64644
        * decl2.c (finish_anon_union): Complain about "anonymous union with
        no members" with a pedwarn.

/testsuite
2017-06-16  Manuel Lopez-Ibanez  <m...@gcc.gnu.org>
            Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/64644
        * g++.dg/other/anon-union4.C: New.
        * g++.old-deja/g++.law/union4.C: Adjust.
        * g++.old-deja/g++.other/anon1.C: Likewise.
Index: cp/decl2.c
===================================================================
--- cp/decl2.c  (revision 249233)
+++ cp/decl2.c  (working copy)
@@ -1559,7 +1559,7 @@ finish_anon_union (tree anon_union_decl)
     return;
   if (main_decl == NULL_TREE)
     {
-      warning (0, "anonymous union with no members");
+      pedwarn (input_location, 0, "anonymous union with no members");
       return;
     }
 
Index: testsuite/g++.dg/other/anon-union4.C
===================================================================
--- testsuite/g++.dg/other/anon-union4.C        (revision 0)
+++ testsuite/g++.dg/other/anon-union4.C        (working copy)
@@ -0,0 +1,3 @@
+// PR c++/64644
+
+static union { };  // { dg-error "anonymous union with no members" }
Index: testsuite/g++.old-deja/g++.law/union4.C
===================================================================
--- testsuite/g++.old-deja/g++.law/union4.C     (revision 249233)
+++ testsuite/g++.old-deja/g++.law/union4.C     (working copy)
@@ -10,4 +10,4 @@ static union {
         struct SS {
                 int ss;
         };
-};// { dg-warning "no members" }
+};// { dg-error "no members" }
Index: testsuite/g++.old-deja/g++.other/anon1.C
===================================================================
--- testsuite/g++.old-deja/g++.other/anon1.C    (revision 249233)
+++ testsuite/g++.old-deja/g++.other/anon1.C    (working copy)
@@ -3,4 +3,4 @@
 static union {
   union {
   };
-}; // { dg-warning "" } anonymous union with no members
+}; // { dg-error "" } anonymous union with no members

Reply via email to