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.
///////////////////////////
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" }