[C/C++ PATCH] PR c++/66572. Fix Wlogical-op false positive

Marek Polacek polacek@redhat.com
Tue Jul 21 11:14:00 GMT 2015


Ping.

On Tue, Jul 14, 2015 at 06:38:12PM +0200, Marek Polacek wrote:
> Ok, in that case I think easiest would the following (I hit the same issue
> when writing the -Wtautological-compare patch):
> 
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
> 
> 2015-07-14  Marek Polacek  <polacek@redhat.com>
> 
> 	PR c++/66572
> 	* pt.c (tsubst_copy_and_build): Add warn_logical_op sentinel.
> 
> 	* g++.dg/warn/Wlogical-op-2.C: New test.
> 
> diff --git gcc/cp/pt.c gcc/cp/pt.c
> index 2097963..0c9712a 100644
> --- gcc/cp/pt.c
> +++ gcc/cp/pt.c
> @@ -14893,6 +14893,7 @@ tsubst_copy_and_build (tree t,
>        {
>  	warning_sentinel s1(warn_type_limits);
>  	warning_sentinel s2(warn_div_by_zero);
> +	warning_sentinel s3(warn_logical_op);
>  	tree op0 = RECUR (TREE_OPERAND (t, 0));
>  	tree op1 = RECUR (TREE_OPERAND (t, 1));
>  	tree r = build_x_binary_op
> diff --git gcc/testsuite/g++.dg/warn/Wlogical-op-2.C gcc/testsuite/g++.dg/warn/Wlogical-op-2.C
> index e69de29..755db08 100644
> --- gcc/testsuite/g++.dg/warn/Wlogical-op-2.C
> +++ gcc/testsuite/g++.dg/warn/Wlogical-op-2.C
> @@ -0,0 +1,30 @@
> +// PR c++/66572
> +// { dg-do compile { target c++11 } }
> +// { dg-options "-Wlogical-op" }
> +
> +struct false_type
> +{
> +    static constexpr bool value = false;
> +};
> +
> +struct true_type
> +{
> +    static constexpr bool value = true;
> +};
> +
> +template<typename T>
> +struct is_unsigned : false_type {};
> +
> +template<>
> +struct is_unsigned<unsigned> : true_type {};
> +
> +template<typename T1, typename T2>
> +bool foo()
> +{
> +    return is_unsigned<T1>::value && is_unsigned<T2>::value;
> +}
> +
> +int main()
> +{
> +    foo<unsigned, unsigned>();
> +}
> 
> 	Marek

	Marek



More information about the Gcc-patches mailing list