The following produces an internal compiler when compiled with -Wall starting with gcc 14: $ cat test.cpp template <class A> class Test { void foo(unsigned x, unsigned y) { bool test = &a[x] == &b[y]; } unsigned *a; unsigned *b; }; $ g++ -Wall ./test.cpp ./test.cpp: In member function 'void Test<A>::foo(unsigned int, unsigned int)': ./test.cpp:4:34: internal compiler error: Segmentation fault 4 | bool test = &a[x] == &b[y]; | ^ Please submit a full bug report, with preprocessed source (by using -freport-bug). See <https://gcc.gnu.org/bugs/> for instructions.
Started with r14-4793: commit dad311874ac3b3cf4eca1c04f67cae80c953f7b8 Author: Patrick Palka <ppalka@redhat.com> Date: Fri Oct 20 10:45:00 2023 -0400 c++: remove NON_DEPENDENT_EXPR, part 1
The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>: https://gcc.gnu.org/g:7ca486889b1b1c7e7bcbbca3b6caa103294ec07d commit r15-3673-g7ca486889b1b1c7e7bcbbca3b6caa103294ec07d Author: Marek Polacek <polacek@redhat.com> Date: Thu Aug 29 10:40:50 2024 -0400 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>
Fixed on trunk so far.
The releases/gcc-14 branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>: https://gcc.gnu.org/g:36de56d3d643e7b8131fa6671b9e85258a1d1ca1 commit r14-10800-g36de56d3d643e7b8131fa6671b9e85258a1d1ca1 Author: Marek Polacek <polacek@redhat.com> Date: Thu Aug 29 10:40:50 2024 -0400 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> (cherry picked from commit 7ca486889b1b1c7e7bcbbca3b6caa103294ec07d)
Fixed.