Patchwork [C++] PR 51786

login
register
mail settings
Submitter Paolo Carlini
Date July 8, 2013, 11:32 p.m.
Message ID <51DB4BFB.6010402@oracle.com>
Download mbox | patch
Permalink /patch/257614/
State New
Headers show

Comments

Paolo Carlini - July 8, 2013, 11:32 p.m.
On 07/08/2013 08:01 PM, Jason Merrill wrote:
> On 07/08/2013 01:49 PM, Paolo Carlini wrote:
>> Ah I see. I take your indication as meaning class *or enum*
> Yes.
Thanks. Thus, as agreed, I tested the below. Ok?

Paolo.

///////////////////////////
Jason Merrill - July 9, 2013, 3:09 a.m.
On 07/08/2013 07:32 PM, Paolo Carlini wrote:
> +	      && (CLASS_TYPE_P (decl_specifiers.type)
> +		  || TREE_CODE (decl_specifiers.type) == ENUMERAL_TYPE))

You can use OVERLOAD_TYPE_P here if you want.  OK either way.

Jason
Paolo Carlini - July 9, 2013, 10:51 a.m.
On 07/09/2013 05:09 AM, Jason Merrill wrote:
> On 07/08/2013 07:32 PM, Paolo Carlini wrote:
>> +          && (CLASS_TYPE_P (decl_specifiers.type)
>> +          || TREE_CODE (decl_specifiers.type) == ENUMERAL_TYPE))
>
> You can use OVERLOAD_TYPE_P here if you want.
Ah, I seemed to remember we had something, but stupidly grepped for 
CLASS_OR_ENUM_TYPE_P and the like ;) Anyway, changed and committed.

Thanks!
Paolo.

Patch

Index: cp/parser.c
===================================================================
--- cp/parser.c	(revision 200780)
+++ cp/parser.c	(working copy)
@@ -11009,11 +11009,21 @@  cp_parser_simple_declaration (cp_parser* parser,
 
   /* Issue an error message if no declarators are present, and the
      decl-specifier-seq does not itself declare a class or
-     enumeration.  */
+     enumeration: [dcl.dcl]/3.  */
   if (!saw_declarator)
     {
       if (cp_parser_declares_only_class_p (parser))
-	shadow_tag (&decl_specifiers);
+	{
+	  if (!declares_class_or_enum
+	      && decl_specifiers.type
+	      && (CLASS_TYPE_P (decl_specifiers.type)
+		  || TREE_CODE (decl_specifiers.type) == ENUMERAL_TYPE))
+	    /* Ensure an error is issued anyway when finish_decltype_type,
+	       called via cp_parser_decl_specifier_seq, returns a class or
+	       an enumeration (c++/51786).  */
+	    decl_specifiers.type = NULL_TREE;
+	  shadow_tag (&decl_specifiers);
+	}
       /* Perform any deferred access checks.  */
       perform_deferred_access_checks (tf_warning_or_error);
     }
Index: testsuite/g++.dg/cpp0x/pr51786.C
===================================================================
--- testsuite/g++.dg/cpp0x/pr51786.C	(revision 0)
+++ testsuite/g++.dg/cpp0x/pr51786.C	(working copy)
@@ -0,0 +1,8 @@ 
+// PR c++/51786
+// { dg-do compile { target c++11 } }
+
+enum E {};
+struct A {};
+
+void foo() { decltype(E{}); }  // { dg-error "does not declare anything" }
+void bar() { decltype(A{}); }  // { dg-error "does not declare anything" }