+2018-08-17 David Malcolm <dmalcolm@redhat.com>
+
+ * typeck.c (string_conv_p): Extract location from EXP and use it
+ in preference to input_location when issuing warnings.
+
2018-08-15 David Malcolm <dmalcolm@redhat.com>
* call.c: Include "gcc-rich-location.h".
&& !same_type_p (t, wchar_type_node))
return 0;
+ location_t loc = EXPR_LOC_OR_LOC (exp, input_location);
+
STRIP_ANY_LOCATION_WRAPPER (exp);
if (TREE_CODE (exp) == STRING_CST)
if (warn)
{
if (cxx_dialect >= cxx11)
- pedwarn (input_location, OPT_Wwrite_strings,
+ pedwarn (loc, OPT_Wwrite_strings,
"ISO C++ forbids converting a string constant to %qT",
totype);
else
- warning (OPT_Wwrite_strings,
- "deprecated conversion from string constant to %qT",
- totype);
+ warning_at (loc, OPT_Wwrite_strings,
+ "deprecated conversion from string constant to %qT",
+ totype);
}
return 1;
+2018-08-17 David Malcolm <dmalcolm@redhat.com>
+
+ * g++.dg/conversion/Wwrite-strings.C: New test.
+
2018-08-17 Sandra Loosemore <sandra@codesourcery.com>
Chung-Lin Tang <cltang@codesourcery.com>
Xianmiao Qu <xianmiao_qu@c-sky.com>
--- /dev/null
+// { dg-options "-fdiagnostics-show-caret" }
+
+/* Verify that -Wwrite-strings underlines the string literal in question. */
+
+extern int callee (const char *one, char *two, const char *three);
+
+int test_1 ()
+{
+ return callee ("first", "second", "third"); // { dg-warning "string constant to 'char\\*'" }
+ /* { dg-begin-multiline-output "" }
+ return callee ("first", "second", "third");
+ ^~~~~~~~
+ { dg-end-multiline-output "" } */
+ // TODO: underline the pertinent param in the decl of callee
+}
+
+char *test_2 (void)
+{
+ return "foo"; // { dg-warning "string constant to 'char\\*'" }
+ /* { dg-begin-multiline-output "" }
+ return "foo";
+ ^~~~~
+ { dg-end-multiline-output "" } */
+}