Patchwork [C++] PR 32054

login
register
mail settings
Submitter Paolo Carlini
Date May 25, 2012, 2:57 a.m.
Message ID <4FBEF51A.7040209@oracle.com>
Download mbox | patch
Permalink /patch/161237/
State New
Headers show

Comments

Paolo Carlini - May 25, 2012, 2:57 a.m.
Hi,

another simple issue, this one remained assigned to me for a while ;) 
Anyway, we are not rejecting storage classes for anonymous unions in 
class scope. Details: I'm handling anonymous structs in the same way, 
for consistency (but in principle being an extension we could do 
nothing); the error message I choose is quite terse (essentially the 
beginning of the Standard wording about this issue); in terms of 
testing, auto is of course special in C++11 (I could also, for example, 
wrap the lines for the auto case in #ifndef __GXX_EXPERIMENTAL_CXX0X__)

Bootstrapped and tested x86_64-linux, as usual.

Thanks,
Paolo.

//////////////////////
/cp
2012-05-25  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/32054
	* parser.c (cp_parser_member_declaration): A storage class is not
	allowed in a declaration of an anonymous union (and struct, as a
	GCC extension) in a class scope.

/testsuite
2012-05-25  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/32054
	* g++.dg/other/anon-union3.C: New.
Jason Merrill - May 25, 2012, 4:25 p.m.
On 05/24/2012 10:57 PM, Paolo Carlini wrote:
> +		error_at (decl_spec_token_start->location,
> +			  "a storage class is not allowed");

Let's give more explanation here so that the user knows that the problem 
is a storage class on an anonymous union/struct in class scope.

Jason

Patch

Index: testsuite/g++.dg/other/anon-union3.C
===================================================================
--- testsuite/g++.dg/other/anon-union3.C	(revision 0)
+++ testsuite/g++.dg/other/anon-union3.C	(revision 0)
@@ -0,0 +1,25 @@ 
+// PR c++/32054
+
+class C
+{
+  auto union      // { dg-error "storage class" "" { target c++98 } }
+    {
+      int a;
+    };            // { dg-error "multiple|specified" "" { target c++11 } }
+  register union  // { dg-error "storage class" }
+    {
+      int b;
+    };
+  static union    // { dg-error "storage class" }
+    {
+      int c;
+    };
+  extern union    // { dg-error "storage class" }
+    {
+      int d;
+    };
+  mutable union   // { dg-error "storage class" }
+    {
+      int e;
+    };
+};
Index: cp/parser.c
===================================================================
--- cp/parser.c	(revision 187868)
+++ cp/parser.c	(working copy)
@@ -18910,6 +18910,11 @@  cp_parser_member_declaration (cp_parser* parser)
 	     particular type), as opposed to a nested class.  */
 	  else if (ANON_AGGR_TYPE_P (type))
 	    {
+	      /* C++11 9.5/6.  */
+	      if (decl_specifiers.storage_class != sc_none)
+		error_at (decl_spec_token_start->location,
+			  "a storage class is not allowed");
+
 	      /* Remove constructors and such from TYPE, now that we
 		 know it is an anonymous aggregate.  */
 	      fixup_anonymous_aggr (type);