Message ID | tkrat.a4ecb77d8251f5df@netcologne.de |
---|---|
State | New |
Headers | show |
On 04/21/2017 12:01 PM, Volker Reichelt wrote: > Hi, > > the following patch adds fix-it info to error messages in 4 places > where the C++ parser complains about duplicate tokens. > The fix-it infos suggest to remove the duplicates. > > Bootstrapped and regtested on x86_64-pc-linux-gnu. > > OK for trunk? > ok
On Fri, 2017-04-21 at 18:01 +0200, Volker Reichelt wrote: > Hi, > > the following patch adds fix-it info to error messages in 4 places > where the C++ parser complains about duplicate tokens. > The fix-it infos suggest to remove the duplicates. > > Bootstrapped and regtested on x86_64-pc-linux-gnu. > > OK for trunk? OK for trunk (with my "diagnostic messages" maintainer hat on). Ideally we'd put a secondary range into each of these messages, via rich_loc.add_range (other_token_loc, false) highlighting the other token, but I don't think the parser retains the pertinent location_t information. Thanks Dave > Regards, > Volker > > > 2017-04-21 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. > > Index: gcc/cp/parser.c > =================================================================== > --- gcc/cp/parser.c (revision 246880) > +++ gcc/cp/parser.c (working copy) > @@ -20258,7 +20258,9 @@ > > 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 @@ > > 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 > @@ -27665,7 +27669,11 @@ > 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 > { > @@ -27686,8 +27694,9 @@ > "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]); > } > } > } > > 2017-04-21 Volker Reichelt <v.reichelt@netcologne.de> > > * g++.dg/diagnostic/duplicate1.C: New test. > * g++.dg/cpp0x/duplicate1.C: New test. > > Index: gcc/testsuite/g++.dg/diagnostic/duplicate1.C > =================================================================== > --- gcc/testsuite/g++.dg/diagnostic/duplicate1.C 2017-04-21 > +++ gcc/testsuite/g++.dg/diagnostic/duplicate1.C 2017-04-21 > @@ -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 "" } */ > Index: gcc/testsuite/g++.dg/cpp0x/duplicate1.C > =================================================================== > --- gcc/testsuite/g++.dg/cpp0x/duplicate1.C 2017-04-21 > +++ gcc/testsuite/g++.dg/cpp0x/duplicate1.C 2017-04-21 > @@ -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 "" } */ > =================================================================== >
Index: gcc/cp/parser.c =================================================================== --- gcc/cp/parser.c (revision 246880) +++ gcc/cp/parser.c (working copy) @@ -20258,7 +20258,9 @@ 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 @@ 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 @@ -27665,7 +27669,11 @@ 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 { @@ -27686,8 +27694,9 @@ "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]); } } } 2017-04-21 Volker Reichelt <v.reichelt@netcologne.de> * g++.dg/diagnostic/duplicate1.C: New test. * g++.dg/cpp0x/duplicate1.C: New test. Index: gcc/testsuite/g++.dg/diagnostic/duplicate1.C =================================================================== --- gcc/testsuite/g++.dg/diagnostic/duplicate1.C 2017-04-21 +++ gcc/testsuite/g++.dg/diagnostic/duplicate1.C 2017-04-21 @@ -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 "" } */ Index: gcc/testsuite/g++.dg/cpp0x/duplicate1.C =================================================================== --- gcc/testsuite/g++.dg/cpp0x/duplicate1.C 2017-04-21 +++ gcc/testsuite/g++.dg/cpp0x/duplicate1.C 2017-04-21 @@ -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 "" } */