]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: ICE with -Wduplicated-branches in template [PR117880]
authorMarek Polacek <polacek@redhat.com>
Mon, 9 Dec 2024 20:36:25 +0000 (15:36 -0500)
committerMarek Polacek <polacek@redhat.com>
Tue, 10 Dec 2024 17:21:02 +0000 (12:21 -0500)
commitd26c166001d6a5bdfd94be6e6d17135669ed340b
tree572ba94c7a187ceff7e83aa8286632a942dce179
parent21fbfae2e55e1a153820acc6fbd922e66f67e65b
c++: ICE with -Wduplicated-branches in template [PR117880]

In a template, for things like void() we'll create a CAST_EXPR with
a null operand.  That causes a crash with -Wduplicated-branches on:

  false ? void() : void();

because we do

  if (warn_duplicated_branches
      && (complain & tf_warning)
      && (arg2 == arg3 || operand_equal_p (arg2, arg3,
                                           OEP_ADDRESS_OF_SAME_FIELD)))

even in a template.  So one way to fix the ICE would be to check
!processing_template_decl.  But we can also do the following and
continue warning even in templates.

This ICE appeared with the removal of NON_DEPENDENT_EXPR; before,
operand_equal_p would bail on this code so there was no problem.

PR c++/117880

gcc/ChangeLog:

* fold-const.cc (operand_compare::operand_equal_p) <case tcc_unary>:
Use OP_SAME_WITH_NULL instead of OP_SAME.

gcc/testsuite/ChangeLog:

* g++.dg/warn/Wduplicated-branches8.C: New test.

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