From ec856f5f8b372d1201ec204876ed078a1c0f1f37 Mon Sep 17 00:00:00 2001 From: Volker Reichelt Date: Mon, 24 Apr 2017 16:43:01 +0000 Subject: [PATCH] parser.c (cp_parser_cv_qualifier_seq_opt): Add fix-it info to error message. * 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 | 7 +++++ gcc/cp/parser.c | 19 +++++++++---- gcc/testsuite/ChangeLog | 5 ++++ gcc/testsuite/g++.dg/cpp0x/duplicate1.C | 29 ++++++++++++++++++++ gcc/testsuite/g++.dg/diagnostic/duplicate1.C | 18 ++++++++++++ 5 files changed, 73 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/duplicate1.C create mode 100644 gcc/testsuite/g++.dg/diagnostic/duplicate1.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 6799e2edad9..317415ca43d 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2017-04-24 Volker Reichelt + + * 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 PR c++/80179 - ICE with initialized flexible array member. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 25788902e16..3efb28c727f 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -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 % 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]); } } } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d8306420fc4..3be6903c7e9 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-04-24 Volker Reichelt + + * g++.dg/diagnostic/duplicate1.C: New test. + * g++.dg/cpp0x/duplicate1.C: New test. + 2017-04-24 Martin Jambor 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 index 00000000000..1545e1cd4b5 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/duplicate1.C @@ -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 index 00000000000..8608fa2637a --- /dev/null +++ b/gcc/testsuite/g++.dg/diagnostic/duplicate1.C @@ -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 "" } */ -- 2.30.2