parser.c (cp_parser_elaborated_type_specifier): Add fix-it to diagnostic of invalid...
authorVolker Reichelt <v.reichelt@netcologne.de>
Tue, 25 Apr 2017 16:12:58 +0000 (16:12 +0000)
committerVolker Reichelt <reichelt@gcc.gnu.org>
Tue, 25 Apr 2017 16:12:58 +0000 (16:12 +0000)
        * parser.c (cp_parser_elaborated_type_specifier): Add fix-it to
        diagnostic of invalid class/struct keyword after enum.

        * g++.dg/cpp0x/enum34.C: New test.

From-SVN: r247254

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

index 9c8ad1077e452b763e10d3c1eeeb6af2b5a8fa07..1a9ca1942b885ed27867ce867cb316a42ad2aa6e 100644 (file)
@@ -1,3 +1,8 @@
+2017-04-25  Volker Reichelt  <v.reichelt@netcologne.de>
+
+       * parser.c (cp_parser_elaborated_type_specifier): Add fix-it to
+       diagnostic of invalid class/struct keyword after enum.
+
 2017-04-25  David Malcolm  <dmalcolm@redhat.com>
 
        * parser.c (cp_parser_member_declaration): Add fix-it hint
index c9780f801db5a43fdd5410d785401ef164fb5a8e..4714bc6cd8958512dcb00a80fce1d92237dd7c7e 100644 (file)
@@ -17270,12 +17270,16 @@ cp_parser_elaborated_type_specifier (cp_parser* parser,
       tag_type = enum_type;
       /* Issue a warning if the `struct' or `class' key (for C++0x scoped
         enums) is used here.  */
-      if (cp_lexer_next_token_is_keyword (parser->lexer, RID_CLASS)
-         || cp_lexer_next_token_is_keyword (parser->lexer, RID_STRUCT))
+      cp_token *token = cp_lexer_peek_token (parser->lexer);
+      if (cp_parser_is_keyword (token, RID_CLASS)
+         || cp_parser_is_keyword (token, RID_STRUCT))
        {
-           pedwarn (input_location, 0, "elaborated-type-specifier "
-                     "for a scoped enum must not use the %qD keyword",
-                     cp_lexer_peek_token (parser->lexer)->u.value);
+         gcc_rich_location richloc (token->location);
+         richloc.add_range (input_location, false);
+         richloc.add_fixit_remove ();
+         pedwarn_at_rich_loc (&richloc, 0, "elaborated-type-specifier for "
+                              "a scoped enum must not use the %qD keyword",
+                              token->u.value);
          /* Consume the `struct' or `class' and parse it anyway.  */
          cp_lexer_consume_token (parser->lexer);
        }
index 1bc68ac3a11bf444785e708810cffd4f6ec0554c..6b1feffebe83e062720b4be8ccc9a9579d3c4aca 100644 (file)
@@ -1,3 +1,7 @@
+2017-04-25  Volker Reichelt  <v.reichelt@netcologne.de>
+
+       * g++.dg/cpp0x/enum34.C: New test.
+
 2017-04-25  Tom de Vries  <tom@codesourcery.com>
 
        * lib/gcc-dg.exp (cleanup-after-saved-dg-test): Cleanup line number
diff --git a/gcc/testsuite/g++.dg/cpp0x/enum34.C b/gcc/testsuite/g++.dg/cpp0x/enum34.C
new file mode 100644 (file)
index 0000000..6bc72de
--- /dev/null
@@ -0,0 +1,11 @@
+// { dg-options "-fdiagnostics-show-caret" }
+// { dg-do compile { target c++11 } }
+
+enum class E;
+
+enum class E e;  /* { dg-warning "scoped enum must not use" }
+  { dg-begin-multiline-output "" }
+ enum class E e;
+ ~~~~ ^~~~~
+      -----
+  { dg-end-multiline-output "" } */