From: Paolo Carlini Date: Tue, 9 Jul 2013 09:28:09 +0000 (+0000) Subject: re PR c++/51786 ([c++0x] Invalid declaration with decltype accepted) X-Git-Tag: releases/gcc-4.9.0~5068 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=22adf7b528f4902febeebc2fb2cb078b33068491;p=thirdparty%2Fgcc.git re PR c++/51786 ([c++0x] Invalid declaration with decltype accepted) /cp 2013-07-09 Paolo Carlini 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 PR c++/51786 * g++.dg/cpp0x/pr51786.C: New. From-SVN: r200813 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 33f6562f1a47..696ef35825fb 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2013-07-09 Paolo Carlini + + PR c++/51786 + * parser.c (cp_parser_simple_declaration): Before calling shadow_tag + also check declares_class_or_enum. + 2013-07-08 Jason Merrill PR c++/57550 diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 05643e46ad85..e2c3c3e95e47 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -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); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6cef4b9d91a6..e73706aee795 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2013-07-09 Paolo Carlini + + PR c++/51786 + * g++.dg/cpp0x/pr51786.C: New. + 2013-07-08 Janis Johnson * 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 index 000000000000..69b7441588fe --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/pr51786.C @@ -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" }