Ping.

On Thu, Aug 29, 2024 at 12:23:35PM -0400, Marek Polacek wrote:
> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk/14?
> 
> -- >8 --
> Pre r14-4793, we'd call warn_tautological_cmp -> operand_equal_p
> with operands wrapped in NON_DEPENDENT_EXPR, which works, since
> o_e_p bails for codes it doesn't know.  But now we pass operands
> not encapsulated in NON_DEPENDENT_EXPR, and crash, because the
> template tree for &a[x] has null DECL_FIELD_OFFSET.
> 
> I don't think I meant this warning to be called in a template,
> so let's avoid the problem this easy way.
> 
>       PR c++/116534
> 
> gcc/cp/ChangeLog:
> 
>       * call.cc (build_new_op) <case NE_EXPR>: Don't call
>       warn_tautological_cmp in a template.
> 
> gcc/testsuite/ChangeLog:
> 
>       * g++.dg/warn/Wtautological-compare4.C: New test.
> ---
>  gcc/cp/call.cc                                |  4 +++-
>  .../g++.dg/warn/Wtautological-compare4.C      | 21 +++++++++++++++++++
>  2 files changed, 24 insertions(+), 1 deletion(-)
>  create mode 100644 gcc/testsuite/g++.dg/warn/Wtautological-compare4.C
> 
> diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc
> index fa7f05d76f6..d0d0c4b4d3c 100644
> --- a/gcc/cp/call.cc
> +++ b/gcc/cp/call.cc
> @@ -7526,7 +7526,9 @@ build_new_op (const op_location_t &loc, enum tree_code 
> code, int flags,
>         && ((code_orig_arg1 == BOOLEAN_TYPE)
>             ^ (code_orig_arg2 == BOOLEAN_TYPE)))
>       maybe_warn_bool_compare (loc, code, arg1, arg2);
> -      if (complain & tf_warning && warn_tautological_compare)
> +      if ((complain & tf_warning)
> +       && warn_tautological_compare
> +       && !processing_template_decl)
>       warn_tautological_cmp (loc, code, arg1, arg2);
>        /* Fall through.  */
>      case SPACESHIP_EXPR:
> diff --git a/gcc/testsuite/g++.dg/warn/Wtautological-compare4.C 
> b/gcc/testsuite/g++.dg/warn/Wtautological-compare4.C
> new file mode 100644
> index 00000000000..96308f49a42
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/warn/Wtautological-compare4.C
> @@ -0,0 +1,21 @@
> +// PR c++/116534
> +// { dg-do compile }
> +// { dg-options "-Wall" }
> +
> +template <class A>
> +struct Test {
> +    bool foo(unsigned x, unsigned y) {
> +        bool test = &a[x] == &b[y];
> +     return test;
> +    }
> +    unsigned *a;
> +    unsigned *b;
> +};
> +
> +void
> +g ()
> +{
> +  Test<int> t;
> +  t.foo (0u, 1u);
> +  t.foo (0u, 0u);
> +}
> 
> base-commit: cdd5dd2125ca850aa8599f76bed02509590541ef
> -- 
> 2.46.0
> 

Marek

Reply via email to