diff options
author | Marek Polacek <polacek@redhat.com> | 2020-10-28 14:45:27 -0400 |
---|---|---|
committer | Marek Polacek <polacek@redhat.com> | 2020-10-28 18:02:05 -0400 |
commit | 24fb1d9c5855900b5229d8db445eba515c8375e3 (patch) | |
tree | d588d145655703722010e4cffffe040a0c0762bf /gcc/cp/parser.c | |
parent | 455ade18462e5076065b1970e21c622239797392 (diff) | |
download | gcc-24fb1d9c5855900b5229d8db445eba515c8375e3.zip gcc-24fb1d9c5855900b5229d8db445eba515c8375e3.tar.gz gcc-24fb1d9c5855900b5229d8db445eba515c8375e3.tar.bz2 |
c++: Improve the MVP -Wparentheses diagnostic.
I noticed that declarator->parenthesized is, for this warning, only set
to the opening paren. But we can easily make it a range and generate
a nicer diagnostic. Moreover, we can then offer a fix-it hint.
TL;DR: This patch changes
mvp3.C:8:7: warning: unnecessary parentheses in declaration of āiā [-Wparentheses]
8 | int (i);
| ^
to
mvp3.C:8:7: warning: unnecessary parentheses in declaration of āiā [-Wparentheses]
8 | int (i);
| ^~~
mvp3.C:8:7: note: remove parentheses
8 | int (i);
| ^~~
| - -
Tested by using -fdiagnostics-generate-patch and verifying that the
generated patch DTRT.
gcc/cp/ChangeLog:
* decl.c (grokdeclarator): Offer a fix-it hint for the "unnecessary
parentheses in declaration" warning.
* parser.c (cp_parser_direct_declarator): When setting
declarator->parenthesized, use a location range.
gcc/testsuite/ChangeLog:
* g++.dg/warn/mvp3.C: New test.
Diffstat (limited to 'gcc/cp/parser.c')
-rw-r--r-- | gcc/cp/parser.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 2340795..d65b408 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -21866,7 +21866,9 @@ cp_parser_direct_declarator (cp_parser* parser, open_paren = NULL; } if (open_paren) - declarator->parenthesized = open_paren->location; + declarator->parenthesized = make_location (open_paren->location, + open_paren->location, + close_paren->location); } /* If we entered a scope, we must exit it now. */ |