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 bogus warning with a non-type argument (PR c++/82541)


OK.

On Tue, Jan 2, 2018 at 9:51 AM, Marek Polacek <polacek@redhat.com> wrote:
> This PR complains about a bogus -Wduplicated-branches warning with a non-type
> template argument.  That can be easily fixed with a new sentinel.  I also
> noticed a missing tf_warning warning check, so I added it for good measure.
>
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
>
> 2018-01-02  Marek Polacek  <polacek@redhat.com>
>
>         PR c++/82541
>         * call.c (build_conditional_expr_1): Check complain before warning.
>         * pt.c (tsubst_copy_and_build) <case COND_EXPR>: Suppress
>         -Wduplicated-branches.
>
>         * g++.dg/warn/Wduplicated-branches4.C: New test.
>
> diff --git gcc/cp/call.c gcc/cp/call.c
> index bd7666d72bb..c23a733978e 100644
> --- gcc/cp/call.c
> +++ gcc/cp/call.c
> @@ -5343,6 +5343,7 @@ build_conditional_expr_1 (location_t loc, tree arg1, tree arg2, tree arg3,
>    /* If the ARG2 and ARG3 are the same and don't have side-effects,
>       warn here, because the COND_EXPR will be turned into ARG2.  */
>    if (warn_duplicated_branches
> +      && (complain & tf_warning)
>        && (arg2 == arg3 || operand_equal_p (arg2, arg3, 0)))
>      warning_at (EXPR_LOCATION (result), OPT_Wduplicated_branches,
>                 "this condition has identical branches");
> diff --git gcc/cp/pt.c gcc/cp/pt.c
> index a8144e85a39..2c216eaebbe 100644
> --- gcc/cp/pt.c
> +++ gcc/cp/pt.c
> @@ -17846,6 +17846,7 @@ tsubst_copy_and_build (tree t,
>             exp2 = RECUR (TREE_OPERAND (t, 2));
>           }
>
> +       warning_sentinel s(warn_duplicated_branches);
>         RETURN (build_x_conditional_expr (EXPR_LOCATION (t),
>                                          cond, exp1, exp2, complain));
>        }
> diff --git gcc/testsuite/g++.dg/warn/Wduplicated-branches4.C gcc/testsuite/g++.dg/warn/Wduplicated-branches4.C
> index e69de29bb2d..7963c9e8ab5 100644
> --- gcc/testsuite/g++.dg/warn/Wduplicated-branches4.C
> +++ gcc/testsuite/g++.dg/warn/Wduplicated-branches4.C
> @@ -0,0 +1,16 @@
> +// PR c++/82541
> +// { dg-do compile }
> +// { dg-options "-Wduplicated-branches" }
> +
> +template<int N>
> +struct AR
> +{
> +    char a1[N > 0 ? N : 1]; // { dg-bogus "this condition has identical branches" }
> +    char a2[N > 0 ? 1 : 1]; // { dg-warning "this condition has identical branches" }
> +};
> +
> +int
> +main ()
> +{
> +    AR<1> w;
> +}
>
>         Marek


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