This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: C++ PATCH to fix -Wpedantic -Werror=write-strings behavior (PR c++/79791)


OK.

On Thu, Mar 2, 2017 at 8:31 AM, Marek Polacek <polacek@redhat.com> wrote:
> This PR complains that the -Wpedantic -Werror=write-strings combination doesn't
> result in an error but in a pedwarn, which I think is a valid point.  The
> principle is that more specific options take precedence over less specific
> options, so e.g. -Wpedantic -Wno-write-strings shouldn't give a -Wwrite-strings
> warning.  -Wwrite-strings is enabled by default for C++:
> c-family/c-opts.c:205:  opts->x_warn_write_strings = c_dialect_cxx ();
> so I think the following patch fixes the problem; the warning will only ever be
> disabled if the user specifies -Wno-write-strings, and in C++11 it will always
> be a pedwarn, so -pedantic-errors works as expected.  I added a bunch of tests
> to further exercise other combinations, too.
>
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
>
> 2017-03-02  Marek Polacek  <polacek@redhat.com>
>
>         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.
>
> diff --git gcc/cp/typeck.c gcc/cp/typeck.c
> index 3216bc41..d111124 100644
> --- gcc/cp/typeck.c
> +++ 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 gcc/testsuite/g++.dg/warn/Wwrite-strings-1.C gcc/testsuite/g++.dg/warn/Wwrite-strings-1.C
> index e69de29..05abca3 100644
> --- gcc/testsuite/g++.dg/warn/Wwrite-strings-1.C
> +++ 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 gcc/testsuite/g++.dg/warn/Wwrite-strings-10.C gcc/testsuite/g++.dg/warn/Wwrite-strings-10.C
> index e69de29..d34b0b0 100644
> --- gcc/testsuite/g++.dg/warn/Wwrite-strings-10.C
> +++ 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 gcc/testsuite/g++.dg/warn/Wwrite-strings-11.C gcc/testsuite/g++.dg/warn/Wwrite-strings-11.C
> index e69de29..11ddcdb 100644
> --- gcc/testsuite/g++.dg/warn/Wwrite-strings-11.C
> +++ 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 gcc/testsuite/g++.dg/warn/Wwrite-strings-12.C gcc/testsuite/g++.dg/warn/Wwrite-strings-12.C
> index e69de29..754a9c8 100644
> --- gcc/testsuite/g++.dg/warn/Wwrite-strings-12.C
> +++ 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 gcc/testsuite/g++.dg/warn/Wwrite-strings-2.C gcc/testsuite/g++.dg/warn/Wwrite-strings-2.C
> index e69de29..53084d9 100644
> --- gcc/testsuite/g++.dg/warn/Wwrite-strings-2.C
> +++ 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 gcc/testsuite/g++.dg/warn/Wwrite-strings-3.C gcc/testsuite/g++.dg/warn/Wwrite-strings-3.C
> index e69de29..6cb9654 100644
> --- gcc/testsuite/g++.dg/warn/Wwrite-strings-3.C
> +++ 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 gcc/testsuite/g++.dg/warn/Wwrite-strings-4.C gcc/testsuite/g++.dg/warn/Wwrite-strings-4.C
> index e69de29..2654c39 100644
> --- gcc/testsuite/g++.dg/warn/Wwrite-strings-4.C
> +++ 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 gcc/testsuite/g++.dg/warn/Wwrite-strings-5.C gcc/testsuite/g++.dg/warn/Wwrite-strings-5.C
> index e69de29..f58ea90 100644
> --- gcc/testsuite/g++.dg/warn/Wwrite-strings-5.C
> +++ 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 gcc/testsuite/g++.dg/warn/Wwrite-strings-6.C gcc/testsuite/g++.dg/warn/Wwrite-strings-6.C
> index e69de29..ff89f38 100644
> --- gcc/testsuite/g++.dg/warn/Wwrite-strings-6.C
> +++ 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 gcc/testsuite/g++.dg/warn/Wwrite-strings-7.C gcc/testsuite/g++.dg/warn/Wwrite-strings-7.C
> index e69de29..13a8291 100644
> --- gcc/testsuite/g++.dg/warn/Wwrite-strings-7.C
> +++ 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 gcc/testsuite/g++.dg/warn/Wwrite-strings-8.C gcc/testsuite/g++.dg/warn/Wwrite-strings-8.C
> index e69de29..df5f283 100644
> --- gcc/testsuite/g++.dg/warn/Wwrite-strings-8.C
> +++ 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 gcc/testsuite/g++.dg/warn/Wwrite-strings-9.C gcc/testsuite/g++.dg/warn/Wwrite-strings-9.C
> index e69de29..5db813b 100644
> --- gcc/testsuite/g++.dg/warn/Wwrite-strings-9.C
> +++ 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" }
>
>         Marek


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]