From e72cb4332ac94ca1067b554ab6a05b5c650e2fce Mon Sep 17 00:00:00 2001 From: jason Date: Mon, 31 Aug 2009 21:08:33 +0000 Subject: [PATCH] PR c++/41127 * parser.c (cp_parser_enum_specifier): Make sure the : is followed by a type-specifier-seq before we commit. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@151246 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/parser.c | 17 +++++++++-------- gcc/testsuite/ChangeLog | 6 ++++++ gcc/testsuite/g++.dg/cpp0x/enum1.C | 2 +- gcc/testsuite/g++.dg/parse/enum5.C | 17 +++++++++++++++++ 5 files changed, 39 insertions(+), 9 deletions(-) create mode 100644 gcc/testsuite/g++.dg/parse/enum5.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 90a5c59..78d075e 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2009-08-31 Jason Merrill + + PR c++/41127 + * parser.c (cp_parser_enum_specifier): Make sure the : is followed by a + type-specifier-seq before we commit. + 2009-08-28 Richard Guenther PR lto/41058 diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index a3e9f0e..64869cd 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -11967,11 +11967,19 @@ cp_parser_enum_specifier (cp_parser* parser) else identifier = make_anon_name (); - /* Check for the `:' that denotes a specified underlying type in C++0x. */ + /* Check for the `:' that denotes a specified underlying type in C++0x. + Note that a ':' could also indicate a bitfield width, however. */ if (cp_lexer_next_token_is (parser->lexer, CPP_COLON)) { cp_decl_specifier_seq type_specifiers; + /* Consume the `:'. */ + cp_lexer_consume_token (parser->lexer); + + /* Parse the type-specifier-seq. */ + cp_parser_type_specifier_seq (parser, /*is_condition=*/false, + &type_specifiers); + /* At this point this is surely not elaborated type specifier. */ if (!cp_parser_parse_definitely (parser)) return NULL_TREE; @@ -11979,15 +11987,8 @@ cp_parser_enum_specifier (cp_parser* parser) if (cxx_dialect == cxx98) maybe_warn_cpp0x ("scoped enums"); - /* Consume the `:'. */ - cp_lexer_consume_token (parser->lexer); - has_underlying_type = true; - /* Parse the type-specifier-seq. */ - cp_parser_type_specifier_seq (parser, /*is_condition=*/false, - &type_specifiers); - /* If that didn't work, stop. */ if (type_specifiers.type != error_mark_node) { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index eba8f6e..67ea0ef 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2009-08-31 Jason Merrill + + PR c++/41127 + * g++.dg/parse/enum5.C: New. + * g++.dg/cpp0x/enum1.C: Adjust expected error. + 2009-08-31 Janus Weil PR fortran/40940 diff --git a/gcc/testsuite/g++.dg/cpp0x/enum1.C b/gcc/testsuite/g++.dg/cpp0x/enum1.C index af691f0..fb03692 100644 --- a/gcc/testsuite/g++.dg/cpp0x/enum1.C +++ b/gcc/testsuite/g++.dg/cpp0x/enum1.C @@ -2,5 +2,5 @@ // { dg-do compile } // { dg-options "-std=gnu++0x" } -enum : { }; // { dg-error "expected type-specifier" } +enum : { }; // { dg-error "expected" } enum : 3 { }; // { dg-error "expected" } diff --git a/gcc/testsuite/g++.dg/parse/enum5.C b/gcc/testsuite/g++.dg/parse/enum5.C new file mode 100644 index 0000000..3ebb02f --- /dev/null +++ b/gcc/testsuite/g++.dg/parse/enum5.C @@ -0,0 +1,17 @@ +// PR c++/41127 + +#define CHAR_BIT 8 +enum EE {ee}; +typedef unsigned int T; + +struct D { + T : sizeof(unsigned int) * CHAR_BIT; // OK + EE : sizeof(EE) * CHAR_BIT; // OK + enum EE : sizeof(EE) * CHAR_BIT; // not OK + enum EE xxxx : sizeof(EE) * CHAR_BIT; // OK + T x : sizeof(unsigned int) * CHAR_BIT; // OK + enum FF {ff} : sizeof(int) * CHAR_BIT; // OK +} element; + +enum EE xx; +EE yy; -- 2.7.4