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.