]> gcc.gnu.org Git - gcc.git/commitdiff
Diagnose string constant conversion to char* in c++11 and above as forbidden, not...
authorVille Voutilainen <ville.voutilainen@gmail.com>
Wed, 26 Nov 2014 15:16:07 +0000 (17:16 +0200)
committerJason Merrill <jason@gcc.gnu.org>
Wed, 26 Nov 2014 15:16:07 +0000 (10:16 -0500)
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
gcc/cp/typeck.c
gcc/testsuite/g++.dg/warn/write-strings-default.C
gcc/testsuite/g++.dg/warn/write-strings.C
gcc/testsuite/g++.old-deja/g++.bob/inherit1.C
gcc/testsuite/g++.old-deja/g++.brendan/template17.C
gcc/testsuite/g++.old-deja/g++.law/temps1.C
gcc/testsuite/g++.old-deja/g++.martin/typedef2.C

index ae43baad92d09152728c5538269dabdd2c7e34b5..e5f6305faf70a22a0013a636aba9f4ac0059348e 100644 (file)
@@ -1,3 +1,10 @@
+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>
 
        * pt.c (lookup_template_variable): Always unknown_type_node.
index e100d70b1f2d7353a4e8292f162566edd85279cb..8b66acc9011e6dbe06195ff104ea0eab5eb2168f 100644 (file)
@@ -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;
 }
index ee6b217185c193886b2c6e0561714b1cb474a1fb..063b303f66039a2108602f768e5645277b628388 100644 (file)
@@ -3,5 +3,5 @@
 
 int main()
 {
-   char* p = "Asgaard";         // { dg-warning "deprecated" }
+   char* p = "Asgaard";         // { dg-warning "deprecated|forbids converting a string constant" }
 }
index 73c814909835254e280cd080a879c0480519ee15..1293e859156ba15812a2090c00fed78d5c2225c8 100644 (file)
@@ -3,5 +3,5 @@
 
 int main()
 {
-   char* p = "Asgaard";         // { dg-warning "deprecated" }
+   char* p = "Asgaard";         // { dg-warning "deprecated|forbids converting a string constant" }
 }
index e75190ba130d70b029b9548208cfa7504659213e..c037a1c0b2d21b76689f3fba94f4cd1291423403 100644 (file)
@@ -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 () {
index 94eaf3d0da2f25ff4583f98f7b13279b19d73927..b8e2a0ba1454ac865b04b4be47ffe14c7ed5e3fd 100644 (file)
@@ -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 }
index bd344b4190c3e5d32b470b34470b33627f0e40d2..5734210cc88f7d6ccc8add46d5c4ec4742ef91cf 100644 (file)
@@ -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 }
index fa31867654e44d0ae4f0431c72a4230595e9a23e..99603cf9251560b731697506c57694bd2282b2b7 100644 (file)
@@ -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" }
 
This page took 0.091798 seconds and 5 git commands to generate.