diff options
author | David Malcolm <dmalcolm@redhat.com> | 2018-08-17 21:56:21 +0000 |
---|---|---|
committer | David Malcolm <dmalcolm@gcc.gnu.org> | 2018-08-17 21:56:21 +0000 |
commit | 505ce5abd48385f1b415b6ed0aed80e5b378249c (patch) | |
tree | beb75700fa738bc1c04197dd61012336a42fd914 /libcpp/macro.c | |
parent | 8bdea5282fffac0643c4111482e85cfa7c6f7e9f (diff) | |
download | gcc-505ce5abd48385f1b415b6ed0aed80e5b378249c.zip gcc-505ce5abd48385f1b415b6ed0aed80e5b378249c.tar.gz gcc-505ce5abd48385f1b415b6ed0aed80e5b378249c.tar.bz2 |
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
Diffstat (limited to 'libcpp/macro.c')
0 files changed, 0 insertions, 0 deletions