Commit aaf176ca by Ville Voutilainen Committed by Jason Merrill

Diagnose string constant conversion to char* in c++11 and above as forbidden, not deprecated.

	Diagnose string constant conversion to char* in c++11 and above
	as forbidden, not deprecated.
	* typeck.c (string_conv_p): Do a pedwarn in c++11 and above,
	change the diagnostic for the Wwrite-strings case for c++11 and above.

From-SVN: r218087
parent 8006f46b
2014-11-26 Ville Voutilainen <ville.voutilainen@gmail.com>
Diagnose string constant conversion to char* in c++11 and above
as forbidden, not deprecated.
* typeck.c (string_conv_p): Do a pedwarn in c++11 and above,
change the diagnostic for the Wwrite-strings case for c++11 and above.
2014-11-24 Jason Merrill <jason@redhat.com> 2014-11-24 Jason Merrill <jason@redhat.com>
* pt.c (lookup_template_variable): Always unknown_type_node. * pt.c (lookup_template_variable): Always unknown_type_node.
......
...@@ -2139,12 +2139,18 @@ string_conv_p (const_tree totype, const_tree exp, int warn) ...@@ -2139,12 +2139,18 @@ string_conv_p (const_tree totype, const_tree exp, int warn)
|| TREE_CODE (TREE_OPERAND (exp, 0)) != STRING_CST) || TREE_CODE (TREE_OPERAND (exp, 0)) != STRING_CST)
return 0; return 0;
} }
/* This warning is not very useful, as it complains about printf. */
if (warn) if (warn)
warning (OPT_Wwrite_strings, {
"deprecated conversion from string constant to %qT", if (cxx_dialect >= cxx11)
totype); pedwarn (input_location,
pedantic ? OPT_Wpedantic : 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);
}
return 1; return 1;
} }
......
...@@ -3,5 +3,5 @@ ...@@ -3,5 +3,5 @@
int main() int main()
{ {
char* p = "Asgaard"; // { dg-warning "deprecated" } char* p = "Asgaard"; // { dg-warning "deprecated|forbids converting a string constant" }
} }
...@@ -3,5 +3,5 @@ ...@@ -3,5 +3,5 @@
int main() int main()
{ {
char* p = "Asgaard"; // { dg-warning "deprecated" } char* p = "Asgaard"; // { dg-warning "deprecated|forbids converting a string constant" }
} }
...@@ -12,7 +12,7 @@ public: ...@@ -12,7 +12,7 @@ public:
class B : public A { class B : public A {
public: public:
char* m1 () { C::m1(); return ""; } // { dg-error "cannot call" } char* m1 () { C::m1(); return ""; } // { dg-error "cannot call" }
// { dg-warning "deprecated" "depr" { target *-*-* } 14 } // { dg-warning "deprecated|forbids converting a string constant" "depr" { target *-*-* } 14 }
}; };
int main () { int main () {
......
...@@ -10,6 +10,6 @@ public: ...@@ -10,6 +10,6 @@ public:
const Regex NDAMName<'L'>::pattern("^[Ll](.*)$", 1);// { dg-error "type/value mismatch" "mismatch" } const Regex NDAMName<'L'>::pattern("^[Ll](.*)$", 1);// { dg-error "type/value mismatch" "mismatch" }
// { dg-message "expected a type" "expected" { target *-*-* } 11 } // { dg-message "expected a type" "expected" { target *-*-* } 11 }
// { dg-warning "deprecated" "depr" { target *-*-* } 11 } // { dg-warning "deprecated|forbids converting a string constant" "depr" { target *-*-* } 11 }
unsigned NDAMName<'L'>::sequence_number = 0;// { dg-error "type/value mismatch" "mismatch" } unsigned NDAMName<'L'>::sequence_number = 0;// { dg-error "type/value mismatch" "mismatch" }
// { dg-message "expected a type" "exp" { target *-*-* } 14 } // { dg-message "expected a type" "exp" { target *-*-* } 14 }
...@@ -16,5 +16,5 @@ struct cookie ...@@ -16,5 +16,5 @@ struct cookie
cookie ( foo * x) { v=x; } cookie ( foo * x) { v=x; }
}; };
cookie cat(&foo("apabepa"));// { dg-warning "deprecated conversion" "dep" } cookie cat(&foo("apabepa"));// { dg-warning "deprecated conversion|forbids converting a string constant" "dep" }
// { dg-warning "taking address of temporary" "add" { target *-*-* } 19 } // { dg-warning "taking address of temporary" "add" { target *-*-* } 19 }
...@@ -3,5 +3,5 @@ ...@@ -3,5 +3,5 @@
// Check implicit conversion from string constants into typedefs // Check implicit conversion from string constants into typedefs
typedef char CHAR; typedef char CHAR;
void f2(CHAR *s=""); // { dg-warning "deprecated" } void f2(CHAR *s=""); // { dg-warning "deprecated|forbids converting a string constant" }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment