C++: -Wwrite-strings: use location of string constant
Consider:
extern int callee (const char *one, char *two, const char *three);
int test ()
{
return callee ("first", "second", "third");
}
for which -Wwrite-strings was emitting:
Wwrite-strings.C: In function 'int test()':
Wwrite-strings.C:10:44: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
10 | return callee ("first", "second", "third");
| ^
This patch fixes the warning so that it underlines the pertinent argument
at the callsite:
Wwrite-strings.C: In function 'int test()':
Wwrite-strings.C:10:27: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
10 | return callee ("first", "second", "third");
| ^~~~~~~~
Ideally we ought to also issue a "note" highlighting the pertinent
parameter within the decl, but that's not readily available, so I'm
saving it for another patch.
gcc/cp/ChangeLog:
* typeck.c (string_conv_p): Extract location from EXP and use it
in preference to input_location when issuing warnings.
gcc/testsuite/ChangeLog:
* g++.dg/conversion/Wwrite-strings.C: New test.
From-SVN: r263635