]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: ICE with -Wtautological-compare in template [PR116534]
authorMarek Polacek <polacek@redhat.com>
Thu, 29 Aug 2024 14:40:50 +0000 (10:40 -0400)
committerMarek Polacek <polacek@redhat.com>
Tue, 17 Sep 2024 20:59:09 +0000 (16:59 -0400)
commit7ca486889b1b1c7e7bcbbca3b6caa103294ec07d
tree04bd06fd4b9c5d2e48c18c82751caa0383dbac6c
parentdfe0d4389a3ce43179563a63046ad3e74d615a08
c++: ICE with -Wtautological-compare in template [PR116534]

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.

This patch extends r12-7797 to cover the case when DECL_FIELD_OFFSET
is null.

PR c++/116534

gcc/ChangeLog:

* fold-const.cc (operand_compare::operand_equal_p): If either
field's DECL_FIELD_OFFSET is null, compare the fields with ==.

gcc/testsuite/ChangeLog:

* g++.dg/warn/Wtautological-compare4.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/fold-const.cc
gcc/testsuite/g++.dg/warn/Wtautological-compare4.C [new file with mode: 0644]