From: Marek Polacek Date: Wed, 2 Sep 2015 21:00:38 +0000 (+0000) Subject: re PR c/67432 (Improve error message on empty enum) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d04ff41777d999fe5f387f46ec8b9cb22422c513;p=gcc.git re PR c/67432 (Improve error message on empty enum) PR c/67432 * c-parser.c (c_parser_enum_specifier): Give a better error for an empty enum. * gcc.dg/pr67432.c: New test. From-SVN: r227421 --- diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 1536b1bb872..47461d18578 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,9 @@ +2015-09-02 Marek Polacek + + PR c/67432 + * c-parser.c (c_parser_enum_specifier): Give a better error for + an empty enum. + 2015-08-18 Trevor Saunders * c-aux-info.c, c-parser.c, c-tree.h: Remove useless typedefs. diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index 1a587986427..11a2b0f9731 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -2555,7 +2555,16 @@ c_parser_enum_specifier (c_parser *parser) location_t decl_loc, value_loc; if (c_parser_next_token_is_not (parser, CPP_NAME)) { - c_parser_error (parser, "expected identifier"); + /* Give a nicer error for "enum {}". */ + if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE) + && !parser->error) + { + error_at (c_parser_peek_token (parser)->location, + "empty enum is invalid"); + parser->error = true; + } + else + c_parser_error (parser, "expected identifier"); c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL); values = error_mark_node; break; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 8c7175f4029..04328535a03 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-09-02 Marek Polacek + + PR c/67432 + * gcc.dg/pr67432.c: New test. + 2015-09-02 Christophe Lyon * lib/target-supports.exp (clear_effective_target_cache): New. diff --git a/gcc/testsuite/gcc.dg/pr67432.c b/gcc/testsuite/gcc.dg/pr67432.c new file mode 100644 index 00000000000..74367a97251 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr67432.c @@ -0,0 +1,6 @@ +/* PR c/67432 */ +/* { dg-do compile } */ + +enum {}; /* { dg-error "empty enum is invalid" } */ +enum E {}; /* { dg-error "empty enum is invalid" } */ +enum F {} e; /* { dg-error "empty enum is invalid" } */