Diagnose string constant conversion to char* in c++11 and above
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 26 Nov 2014 15:16:07 +0000 (15:16 +0000)
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 26 Nov 2014 15:16:07 +0000 (15:16 +0000)
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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@218087 138bc75d-0d04-0410-961f-82ee72b054a4

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 ae43baa..e5f6305 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 e100d70..8b66acc 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 ee6b217..063b303 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 73c8149..1293e85 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 e75190b..c037a1c 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 94eaf3d..b8e2a0b 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 bd344b4..5734210 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 fa31867..99603cf 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" }