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
| Name |
Last commit
|
Last update |
|---|---|---|
| .. | ||
| Wwrite-strings.C | Loading commit data... | |
| access1.C | Loading commit data... | |
| ambig1.C | Loading commit data... | |
| ambig2.C | Loading commit data... | |
| ambig3.C | Loading commit data... | |
| base1.C | Loading commit data... | |
| bitfield1.C | Loading commit data... | |
| bitfield10.C | Loading commit data... | |
| bitfield11.C | Loading commit data... | |
| bitfield2.C | Loading commit data... | |
| bitfield3.C | Loading commit data... | |
| bitfield4.C | Loading commit data... | |
| bitfield5.C | Loading commit data... | |
| bitfield6.C | Loading commit data... | |
| bitfield7.C | Loading commit data... | |
| bitfield8.C | Loading commit data... | |
| bitfield9.C | Loading commit data... | |
| cast1.C | Loading commit data... | |
| cast2.C | Loading commit data... | |
| cast3.C | Loading commit data... | |
| cond1.C | Loading commit data... | |
| cond2.C | Loading commit data... | |
| cond3.C | Loading commit data... | |
| cond4.C | Loading commit data... | |
| cond6.C | Loading commit data... | |
| const1.C | Loading commit data... | |
| const2.C | Loading commit data... | |
| const3.C | Loading commit data... | |
| dr195-1.C | Loading commit data... | |
| dr195.C | Loading commit data... | |
| dynamic1.C | Loading commit data... | |
| enum1.C | Loading commit data... | |
| err-recover1.C | Loading commit data... | |
| memfn1.C | Loading commit data... | |
| memfn2.C | Loading commit data... | |
| nullptr1.C | Loading commit data... | |
| nullptr2.C | Loading commit data... | |
| op1.C | Loading commit data... | |
| op2.C | Loading commit data... | |
| op3.C | Loading commit data... | |
| op4.C | Loading commit data... | |
| op5.C | Loading commit data... | |
| op6.C | Loading commit data... | |
| pr16333.C | Loading commit data... | |
| pr41426.C | Loading commit data... | |
| pr59879.C | Loading commit data... | |
| pr66211.C | Loading commit data... | |
| pr66895.C | Loading commit data... | |
| ptrmem1.C | Loading commit data... | |
| ptrmem2.C | Loading commit data... | |
| ptrmem3.C | Loading commit data... | |
| ptrmem4.C | Loading commit data... | |
| ptrmem5.C | Loading commit data... | |
| ptrmem6.C | Loading commit data... | |
| ptrmem7.C | Loading commit data... | |
| ptrmem8.C | Loading commit data... | |
| ptrmem9.C | Loading commit data... | |
| ref1.C | Loading commit data... | |
| reinterpret1.C | Loading commit data... | |
| reinterpret2.C | Loading commit data... | |
| reinterpret3.C | Loading commit data... | |
| reinterpret4.C | Loading commit data... | |
| self1.C | Loading commit data... | |
| simd1.C | Loading commit data... | |
| simd2.C | Loading commit data... | |
| simd3.C | Loading commit data... | |
| simd4.C | Loading commit data... | |
| to-virtual-base-1.C | Loading commit data... | |
| void1.C | Loading commit data... | |
| void2.C | Loading commit data... |