]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/51786 ([c++0x] Invalid declaration with decltype accepted)
authorPaolo Carlini <paolo.carlini@oracle.com>
Tue, 9 Jul 2013 09:28:09 +0000 (09:28 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Tue, 9 Jul 2013 09:28:09 +0000 (09:28 +0000)
/cp
2013-07-09  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/51786
* parser.c (cp_parser_simple_declaration): Before calling shadow_tag
also check declares_class_or_enum.

/testsuite
2013-07-09  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/51786
* g++.dg/cpp0x/pr51786.C: New.

From-SVN: r200813

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/pr51786.C [new file with mode: 0644]

index 33f6562f1a4715b4c2b059fb5256db04a505cdcc..696ef35825fb6f1ad94702191e9982398f942212 100644 (file)
@@ -1,3 +1,9 @@
+2013-07-09  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/51786
+       * parser.c (cp_parser_simple_declaration): Before calling shadow_tag
+       also check declares_class_or_enum.
+
 2013-07-08  Jason Merrill  <jason@redhat.com>
 
        PR c++/57550
index 05643e46ad85ac0ec5ccf063c53f0cd3fbc78e7a..e2c3c3e95e47dcba81d8e874cc4d8a3066b01784 100644 (file)
@@ -11009,11 +11009,20 @@ 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
+             && OVERLOAD_TYPE_P (decl_specifiers.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 6cef4b9d91a6a61fdf5848b0b614e3c5c765f28f..e73706aee795fe8a496dc16a9194646ed372aa79 100644 (file)
@@ -1,3 +1,8 @@
+2013-07-09  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/51786
+       * g++.dg/cpp0x/pr51786.C: New.
+
 2013-07-08  Janis Johnson  <janisjo@codesourcery.com>
 
        * gcc.target/powerpc/tfmode_off.c: Skip for EABI targets.
diff --git a/gcc/testsuite/g++.dg/cpp0x/pr51786.C b/gcc/testsuite/g++.dg/cpp0x/pr51786.C
new file mode 100644 (file)
index 0000000..69b7441
--- /dev/null
@@ -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" }