re PR c/67432 (Improve error message on empty enum)
authorMarek Polacek <polacek@redhat.com>
Wed, 2 Sep 2015 21:00:38 +0000 (21:00 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Wed, 2 Sep 2015 21:00:38 +0000 (21:00 +0000)
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

gcc/c/ChangeLog
gcc/c/c-parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr67432.c [new file with mode: 0644]

index 1536b1bb872d38e5770557b4fad6020f0d0b6aa6..47461d18578695716d03e5f91c19f230a2b77f74 100644 (file)
@@ -1,3 +1,9 @@
+2015-09-02  Marek Polacek  <polacek@redhat.com>
+
+       PR c/67432
+       * c-parser.c (c_parser_enum_specifier): Give a better error for
+       an empty enum.
+
 2015-08-18  Trevor Saunders  <tbsaunde@tbsaunde.org>
 
        * c-aux-info.c, c-parser.c, c-tree.h: Remove useless typedefs.
index 1a587986427f1fa4b56b5ce73f75c86534f2f439..11a2b0f9731c186032f5fc7e06c1a2f7b27b4be7 100644 (file)
@@ -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;
index 8c7175f402963292cd4efd59d97a8039b6e3eda6..04328535a034abf749fa9603bca264e3fb38cd6e 100644 (file)
@@ -1,3 +1,8 @@
+2015-09-02  Marek Polacek  <polacek@redhat.com>
+
+       PR c/67432
+       * gcc.dg/pr67432.c: New test.
+
 2015-09-02  Christophe Lyon  <christophe.lyon@linaro.org>
 
        * 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 (file)
index 0000000..74367a9
--- /dev/null
@@ -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" } */