Tested on Linux-x64. Remotely related to pr50645, which we should
probably close as invalid.

/cp
2014-11-26  Ville Voutilainen  <ville.voutilai...@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.

/testsuite
2014-11-26  Ville Voutilainen  <ville.voutilai...@gmail.com>

    Diagnose string constant conversion to char* in c++11 and above
    as forbidden, not deprecated.
    * g++.dg/warn/write-strings-default.C: Adjust.
    * g++.dg/warn/write-strings.C: Adjust.
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 7156851..c7d422a 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -2139,12 +2139,24 @@ 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 (warn) {
+    if (cxx_dialect >= cxx11)
+      {
+       if (pedantic)
+         pedwarn (input_location, OPT_Wpedantic,
+                  "ISO C++ forbids converting a string constant to %qT",
+                  totype);
+       else
+         warning (OPT_Wwrite_strings,
+                  "ISO C++ forbids converting a string constant to %qT",
+                  totype);
+      }
+    /* This warning is not very useful, as it complains about printf.  */
+    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 ee6b217..063b303 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 73c8149..1293e85 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" }
 }

Reply via email to