parser.c (cp_parser_cv_qualifier_seq_opt): Add fix-it info to error message.
authorVolker Reichelt <v.reichelt@netcologne.de>
Mon, 24 Apr 2017 16:43:01 +0000 (16:43 +0000)
committerVolker Reichelt <reichelt@gcc.gnu.org>
Mon, 24 Apr 2017 16:43:01 +0000 (16:43 +0000)
        * parser.c (cp_parser_cv_qualifier_seq_opt): Add fix-it info to
        error message.
        (cp_parser_virt_specifier_seq_opt): Likewise.
        (set_and_check_decl_spec_loc): Likewise twice.

        * g++.dg/diagnostic/duplicate1.C: New test.
        * g++.dg/cpp0x/duplicate1.C: New test.

From-SVN: r247105

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

index 6799e2edad9b166130253e4b9428f4cf10c937eb..317415ca43d3965351a52b23f481337526db41b1 100644 (file)
@@ -1,3 +1,10 @@
+2017-04-24  Volker Reichelt  <v.reichelt@netcologne.de>
+
+       * parser.c (cp_parser_cv_qualifier_seq_opt): Add fix-it info to
+       error message.
+       (cp_parser_virt_specifier_seq_opt): Likewise.
+       (set_and_check_decl_spec_loc): Likewise twice.
+
 2017-04-21  Jason Merrill  <jason@redhat.com>
 
        PR c++/80179 - ICE with initialized flexible array member.
index 25788902e1679375a915987a6451214cf7dbf691..3efb28c727f3159a115e56b8a688045fe8bb9063 100644 (file)
@@ -20258,7 +20258,9 @@ cp_parser_cv_qualifier_seq_opt (cp_parser* parser)
 
       if (cv_quals & cv_qualifier)
        {
-         error_at (token->location, "duplicate cv-qualifier");
+         gcc_rich_location richloc (token->location);
+         richloc.add_fixit_remove ();
+         error_at_rich_loc (&richloc, "duplicate cv-qualifier");
          cp_lexer_purge_token (parser->lexer);
        }
       else
@@ -20405,7 +20407,9 @@ cp_parser_virt_specifier_seq_opt (cp_parser* parser)
 
       if (virt_specifiers & virt_specifier)
        {
-         error_at (token->location, "duplicate virt-specifier");
+         gcc_rich_location richloc (token->location);
+         richloc.add_fixit_remove ();
+         error_at_rich_loc (&richloc, "duplicate virt-specifier");
          cp_lexer_purge_token (parser->lexer);
        }
       else
@@ -27677,7 +27681,11 @@ set_and_check_decl_spec_loc (cp_decl_specifier_seq *decl_specs,
            error_at (location,
                      "both %<__thread%> and %<thread_local%> specified");
          else
-           error_at (location, "duplicate %qD", token->u.value);
+           {
+             gcc_rich_location richloc (location);
+             richloc.add_fixit_remove ();
+             error_at_rich_loc (&richloc, "duplicate %qD", token->u.value);
+           }
        }
       else
        {
@@ -27698,8 +27706,9 @@ set_and_check_decl_spec_loc (cp_decl_specifier_seq *decl_specs,
             "constexpr",
            "__complex"
          };
-         error_at (location,
-                   "duplicate %qs", decl_spec_names[ds]);
+         gcc_rich_location richloc (location);
+         richloc.add_fixit_remove ();
+         error_at_rich_loc (&richloc, "duplicate %qs", decl_spec_names[ds]);
        }
     }
 }
index d8306420fc4100ab13f13207b08044d39112e26d..3be6903c7e961ef1f9f1fbfe94ab05e141b9d814 100644 (file)
@@ -1,3 +1,8 @@
+2017-04-24  Volker Reichelt  <v.reichelt@netcologne.de>
+
+       * g++.dg/diagnostic/duplicate1.C: New test.
+       * g++.dg/cpp0x/duplicate1.C: New test.
+
 2017-04-24  Martin Jambor  <mjambor@suse.cz>
 
        PR tree-optimization/80293
diff --git a/gcc/testsuite/g++.dg/cpp0x/duplicate1.C b/gcc/testsuite/g++.dg/cpp0x/duplicate1.C
new file mode 100644 (file)
index 0000000..1545e1c
--- /dev/null
@@ -0,0 +1,29 @@
+// { dg-options "-fdiagnostics-show-caret" }
+// { dg-do compile { target c++11 } }
+
+struct A
+{
+  virtual void foo() const;
+};
+
+struct B final final : A  /* { dg-error "duplicate virt-specifier" }
+  { dg-begin-multiline-output "" }
+ struct B final final : A
+                ^~~~~
+                -----
+  { dg-end-multiline-output "" } */
+{
+  virtual void foo() const override final override;  /* { dg-error "duplicate virt-specifier" }
+  { dg-begin-multiline-output "" }
+   virtual void foo() const override final override;
+                                           ^~~~~~~~
+                                           --------
+  { dg-end-multiline-output "" } */
+};
+
+thread_local thread_local int i = 0;  /* { dg-error "duplicate" }
+  { dg-begin-multiline-output "" }
+ thread_local thread_local int i = 0;
+              ^~~~~~~~~~~~
+              ------------
+  { dg-end-multiline-output "" } */
diff --git a/gcc/testsuite/g++.dg/diagnostic/duplicate1.C b/gcc/testsuite/g++.dg/diagnostic/duplicate1.C
new file mode 100644 (file)
index 0000000..8608fa2
--- /dev/null
@@ -0,0 +1,18 @@
+// { dg-options "-fdiagnostics-show-caret" }
+
+struct A
+{
+  void foo() const const;  /* { dg-error "duplicate cv-qualifier" }
+  { dg-begin-multiline-output "" }
+   void foo() const const;
+                    ^~~~~
+                    -----
+  { dg-end-multiline-output "" } */
+};
+
+volatile volatile int i = 0;  /* { dg-error "duplicate" }
+  { dg-begin-multiline-output "" }
+ volatile volatile int i = 0;
+          ^~~~~~~~
+          --------
+  { dg-end-multiline-output "" } */