From 7278b0a266909c8558e83a4fa91fd0588e92fa1c Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Fri, 3 Mar 2017 09:58:10 +0000 Subject: [PATCH] re PR c++/79791 (-Werror=write-strings ignored with -Wpedantic) PR c++/79791 * typeck.c (string_conv_p): In C++11, always call pedwarn with OPT_Wwrite_strings. * g++.dg/warn/Wwrite-strings-1.C: New test. * g++.dg/warn/Wwrite-strings-2.C: New test. * g++.dg/warn/Wwrite-strings-3.C: New test. * g++.dg/warn/Wwrite-strings-4.C: New test. * g++.dg/warn/Wwrite-strings-5.C: New test. * g++.dg/warn/Wwrite-strings-6.C: New test. * g++.dg/warn/Wwrite-strings-7.C: New test. * g++.dg/warn/Wwrite-strings-8.C: New test. * g++.dg/warn/Wwrite-strings-9.C: New test. * g++.dg/warn/Wwrite-strings-10.C: New test. * g++.dg/warn/Wwrite-strings-11.C: New test. * g++.dg/warn/Wwrite-strings-12.C: New test. From-SVN: r245864 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/typeck.c | 3 +-- gcc/testsuite/ChangeLog | 16 ++++++++++++++++ gcc/testsuite/g++.dg/warn/Wwrite-strings-1.C | 5 +++++ gcc/testsuite/g++.dg/warn/Wwrite-strings-10.C | 5 +++++ gcc/testsuite/g++.dg/warn/Wwrite-strings-11.C | 5 +++++ gcc/testsuite/g++.dg/warn/Wwrite-strings-12.C | 6 ++++++ gcc/testsuite/g++.dg/warn/Wwrite-strings-2.C | 5 +++++ gcc/testsuite/g++.dg/warn/Wwrite-strings-3.C | 5 +++++ gcc/testsuite/g++.dg/warn/Wwrite-strings-4.C | 6 ++++++ gcc/testsuite/g++.dg/warn/Wwrite-strings-5.C | 6 ++++++ gcc/testsuite/g++.dg/warn/Wwrite-strings-6.C | 6 ++++++ gcc/testsuite/g++.dg/warn/Wwrite-strings-7.C | 5 +++++ gcc/testsuite/g++.dg/warn/Wwrite-strings-8.C | 5 +++++ gcc/testsuite/g++.dg/warn/Wwrite-strings-9.C | 5 +++++ 15 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/warn/Wwrite-strings-1.C create mode 100644 gcc/testsuite/g++.dg/warn/Wwrite-strings-10.C create mode 100644 gcc/testsuite/g++.dg/warn/Wwrite-strings-11.C create mode 100644 gcc/testsuite/g++.dg/warn/Wwrite-strings-12.C create mode 100644 gcc/testsuite/g++.dg/warn/Wwrite-strings-2.C create mode 100644 gcc/testsuite/g++.dg/warn/Wwrite-strings-3.C create mode 100644 gcc/testsuite/g++.dg/warn/Wwrite-strings-4.C create mode 100644 gcc/testsuite/g++.dg/warn/Wwrite-strings-5.C create mode 100644 gcc/testsuite/g++.dg/warn/Wwrite-strings-6.C create mode 100644 gcc/testsuite/g++.dg/warn/Wwrite-strings-7.C create mode 100644 gcc/testsuite/g++.dg/warn/Wwrite-strings-8.C create mode 100644 gcc/testsuite/g++.dg/warn/Wwrite-strings-9.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index be98880c963..7ff2827e502 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2017-03-03 Marek Polacek + + PR c++/79791 + * typeck.c (string_conv_p): In C++11, always call pedwarn with + OPT_Wwrite_strings. + 2017-03-02 Jason Merrill Update overload resolution with deduction guides. diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 3216bc41edf..d1111248dc7 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -2175,8 +2175,7 @@ string_conv_p (const_tree totype, const_tree exp, int warn) if (warn) { if (cxx_dialect >= cxx11) - pedwarn (input_location, - pedantic ? OPT_Wpedantic : OPT_Wwrite_strings, + pedwarn (input_location, OPT_Wwrite_strings, "ISO C++ forbids converting a string constant to %qT", totype); else diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index e5a08ac0290..502a0736b34 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,19 @@ +2017-03-03 Marek Polacek + + PR c++/79791 + * g++.dg/warn/Wwrite-strings-1.C: New test. + * g++.dg/warn/Wwrite-strings-2.C: New test. + * g++.dg/warn/Wwrite-strings-3.C: New test. + * g++.dg/warn/Wwrite-strings-4.C: New test. + * g++.dg/warn/Wwrite-strings-5.C: New test. + * g++.dg/warn/Wwrite-strings-6.C: New test. + * g++.dg/warn/Wwrite-strings-7.C: New test. + * g++.dg/warn/Wwrite-strings-8.C: New test. + * g++.dg/warn/Wwrite-strings-9.C: New test. + * g++.dg/warn/Wwrite-strings-10.C: New test. + * g++.dg/warn/Wwrite-strings-11.C: New test. + * g++.dg/warn/Wwrite-strings-12.C: New test. + 2017-03-03 Richard Biener PR middle-end/79818 diff --git a/gcc/testsuite/g++.dg/warn/Wwrite-strings-1.C b/gcc/testsuite/g++.dg/warn/Wwrite-strings-1.C new file mode 100644 index 00000000000..05abca3a2d9 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wwrite-strings-1.C @@ -0,0 +1,5 @@ +// PR c++/79791 +// { dg-do compile { target c++11 } } +// { dg-options "" } + +char *s = "foo"; // { dg-warning "ISO C\\+\\+ forbids converting a string constant" } diff --git a/gcc/testsuite/g++.dg/warn/Wwrite-strings-10.C b/gcc/testsuite/g++.dg/warn/Wwrite-strings-10.C new file mode 100644 index 00000000000..d34b0b065fd --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wwrite-strings-10.C @@ -0,0 +1,5 @@ +// PR c++/79791 +// { dg-do compile { target { ! c++11 } } } +// { dg-options "" } + +char *s = "foo"; // { dg-warning "deprecated conversion from string constant" } diff --git a/gcc/testsuite/g++.dg/warn/Wwrite-strings-11.C b/gcc/testsuite/g++.dg/warn/Wwrite-strings-11.C new file mode 100644 index 00000000000..11ddcdbb23c --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wwrite-strings-11.C @@ -0,0 +1,5 @@ +// PR c++/79791 +// { dg-do compile { target { ! c++11 } } } +// { dg-options "-pedantic-errors" } + +char *s = "foo"; // { dg-warning "deprecated conversion from string constant" } diff --git a/gcc/testsuite/g++.dg/warn/Wwrite-strings-12.C b/gcc/testsuite/g++.dg/warn/Wwrite-strings-12.C new file mode 100644 index 00000000000..754a9c8983b --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wwrite-strings-12.C @@ -0,0 +1,6 @@ +// PR c++/79791 +// { dg-do compile { target { ! c++11 } } } +// { dg-options "-Werror=write-strings" } +// { dg-message "some warnings being treated as errors" "" { target *-*-* } 0 } + +char *s = "foo"; // { dg-error "deprecated conversion from string constant" } diff --git a/gcc/testsuite/g++.dg/warn/Wwrite-strings-2.C b/gcc/testsuite/g++.dg/warn/Wwrite-strings-2.C new file mode 100644 index 00000000000..53084d9d53f --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wwrite-strings-2.C @@ -0,0 +1,5 @@ +// PR c++/79791 +// { dg-do compile { target c++11 } } +// { dg-options "-pedantic-errors" } + +char *s = "foo"; // { dg-error "ISO C\\+\\+ forbids converting a string constant" } diff --git a/gcc/testsuite/g++.dg/warn/Wwrite-strings-3.C b/gcc/testsuite/g++.dg/warn/Wwrite-strings-3.C new file mode 100644 index 00000000000..6cb96547fba --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wwrite-strings-3.C @@ -0,0 +1,5 @@ +// PR c++/79791 +// { dg-do compile { target c++11 } } +// { dg-options "-pedantic-errors -Wno-write-strings" } + +char *s = "foo"; diff --git a/gcc/testsuite/g++.dg/warn/Wwrite-strings-4.C b/gcc/testsuite/g++.dg/warn/Wwrite-strings-4.C new file mode 100644 index 00000000000..2654c395b31 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wwrite-strings-4.C @@ -0,0 +1,6 @@ +// PR c++/79791 +// { dg-do compile { target c++11 } } +// { dg-options "-Werror=write-strings" } +// { dg-message "some warnings being treated as errors" "" { target *-*-* } 0 } + +char *s = "foo"; // { dg-error "ISO C\\+\\+ forbids converting a string constant" } diff --git a/gcc/testsuite/g++.dg/warn/Wwrite-strings-5.C b/gcc/testsuite/g++.dg/warn/Wwrite-strings-5.C new file mode 100644 index 00000000000..f58ea908a37 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wwrite-strings-5.C @@ -0,0 +1,6 @@ +// PR c++/79791 +// { dg-do compile { target c++11 } } +// { dg-options "-Werror=write-strings -Wpedantic" } +// { dg-message "some warnings being treated as errors" "" { target *-*-* } 0 } + +char *s = "foo"; // { dg-error "ISO C\\+\\+ forbids converting a string constant" } diff --git a/gcc/testsuite/g++.dg/warn/Wwrite-strings-6.C b/gcc/testsuite/g++.dg/warn/Wwrite-strings-6.C new file mode 100644 index 00000000000..ff89f3894bc --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wwrite-strings-6.C @@ -0,0 +1,6 @@ +// PR c++/79791 +// { dg-do compile { target c++11 } } +// { dg-options "-Werror=write-strings -Wno-pedantic" } +// { dg-message "some warnings being treated as errors" "" { target *-*-* } 0 } + +char *s = "foo"; // { dg-error "ISO C\\+\\+ forbids converting a string constant" } diff --git a/gcc/testsuite/g++.dg/warn/Wwrite-strings-7.C b/gcc/testsuite/g++.dg/warn/Wwrite-strings-7.C new file mode 100644 index 00000000000..13a8291aedc --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wwrite-strings-7.C @@ -0,0 +1,5 @@ +// PR c++/79791 +// { dg-do compile { target c++11 } } +// { dg-options "-Wno-write-strings" } + +char *s = "foo"; diff --git a/gcc/testsuite/g++.dg/warn/Wwrite-strings-8.C b/gcc/testsuite/g++.dg/warn/Wwrite-strings-8.C new file mode 100644 index 00000000000..df5f28356ee --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wwrite-strings-8.C @@ -0,0 +1,5 @@ +// PR c++/79791 +// { dg-do compile { target c++11 } } +// { dg-options "-Wpedantic -Wno-write-strings" } + +char *s = "foo"; diff --git a/gcc/testsuite/g++.dg/warn/Wwrite-strings-9.C b/gcc/testsuite/g++.dg/warn/Wwrite-strings-9.C new file mode 100644 index 00000000000..5db813b97ab --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wwrite-strings-9.C @@ -0,0 +1,5 @@ +// PR c++/79791 +// { dg-do compile { target c++11 } } +// { dg-options "-Wno-error=write-strings -pedantic-errors" } + +char *s = "foo"; // { dg-warning "ISO C\\+\\+ forbids converting a string constant" } -- 2.30.2