From aaf176ca1896931ac8777c0fd527b0198032b38e Mon Sep 17 00:00:00 2001 From: Ville Voutilainen Date: Wed, 26 Nov 2014 17:16:07 +0200 Subject: [PATCH] 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 --- gcc/cp/ChangeLog | 7 +++++++ gcc/cp/typeck.c | 16 +++++++++++----- .../g++.dg/warn/write-strings-default.C | 2 +- gcc/testsuite/g++.dg/warn/write-strings.C | 2 +- gcc/testsuite/g++.old-deja/g++.bob/inherit1.C | 2 +- .../g++.old-deja/g++.brendan/template17.C | 2 +- gcc/testsuite/g++.old-deja/g++.law/temps1.C | 2 +- gcc/testsuite/g++.old-deja/g++.martin/typedef2.C | 2 +- 8 files changed, 24 insertions(+), 11 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index ae43baad92d..e5f6305faf7 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2014-11-26 Ville Voutilainen + + 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 * pt.c (lookup_template_variable): Always unknown_type_node. diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index e100d70b1f2..8b66acc9011 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -2139,12 +2139,18 @@ string_conv_p (const_tree totype, const_tree exp, int warn) || TREE_CODE (TREE_OPERAND (exp, 0)) != STRING_CST) return 0; } - - /* This warning is not very useful, as it complains about printf. */ if (warn) - warning (OPT_Wwrite_strings, - "deprecated conversion from string constant to %qT", - totype); + { + if (cxx_dialect >= cxx11) + 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; } diff --git a/gcc/testsuite/g++.dg/warn/write-strings-default.C b/gcc/testsuite/g++.dg/warn/write-strings-default.C index ee6b217185c..063b303f660 100644 --- a/gcc/testsuite/g++.dg/warn/write-strings-default.C +++ b/gcc/testsuite/g++.dg/warn/write-strings-default.C @@ -3,5 +3,5 @@ int main() { - char* p = "Asgaard"; // { dg-warning "deprecated" } + char* p = "Asgaard"; // { dg-warning "deprecated|forbids converting a string constant" } } diff --git a/gcc/testsuite/g++.dg/warn/write-strings.C b/gcc/testsuite/g++.dg/warn/write-strings.C index 73c81490983..1293e859156 100644 --- a/gcc/testsuite/g++.dg/warn/write-strings.C +++ b/gcc/testsuite/g++.dg/warn/write-strings.C @@ -3,5 +3,5 @@ int main() { - char* p = "Asgaard"; // { dg-warning "deprecated" } + char* p = "Asgaard"; // { dg-warning "deprecated|forbids converting a string constant" } } diff --git a/gcc/testsuite/g++.old-deja/g++.bob/inherit1.C b/gcc/testsuite/g++.old-deja/g++.bob/inherit1.C index e75190ba130..c037a1c0b2d 100644 --- a/gcc/testsuite/g++.old-deja/g++.bob/inherit1.C +++ b/gcc/testsuite/g++.old-deja/g++.bob/inherit1.C @@ -12,7 +12,7 @@ public: class B : public A { public: 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 () { diff --git a/gcc/testsuite/g++.old-deja/g++.brendan/template17.C b/gcc/testsuite/g++.old-deja/g++.brendan/template17.C index 94eaf3d0da2..b8e2a0ba145 100644 --- a/gcc/testsuite/g++.old-deja/g++.brendan/template17.C +++ b/gcc/testsuite/g++.old-deja/g++.brendan/template17.C @@ -10,6 +10,6 @@ public: const Regex NDAMName<'L'>::pattern("^[Ll](.*)$", 1);// { dg-error "type/value mismatch" "mismatch" } // { 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" } // { dg-message "expected a type" "exp" { target *-*-* } 14 } diff --git a/gcc/testsuite/g++.old-deja/g++.law/temps1.C b/gcc/testsuite/g++.old-deja/g++.law/temps1.C index bd344b4190c..5734210cc88 100644 --- a/gcc/testsuite/g++.old-deja/g++.law/temps1.C +++ b/gcc/testsuite/g++.old-deja/g++.law/temps1.C @@ -16,5 +16,5 @@ struct cookie 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 } diff --git a/gcc/testsuite/g++.old-deja/g++.martin/typedef2.C b/gcc/testsuite/g++.old-deja/g++.martin/typedef2.C index fa31867654e..99603cf9251 100644 --- a/gcc/testsuite/g++.old-deja/g++.martin/typedef2.C +++ b/gcc/testsuite/g++.old-deja/g++.martin/typedef2.C @@ -3,5 +3,5 @@ // Check implicit conversion from string constants into typedefs typedef char CHAR; -void f2(CHAR *s=""); // { dg-warning "deprecated" } +void f2(CHAR *s=""); // { dg-warning "deprecated|forbids converting a string constant" } -- 2.30.2