c++: ICE in value_dependent_expression_p in C++98 mode [PR94938]
authorMarek Polacek <polacek@redhat.com>
Mon, 4 May 2020 22:34:38 +0000 (18:34 -0400)
committerMarek Polacek <polacek@redhat.com>
Wed, 6 May 2020 22:52:44 +0000 (18:52 -0400)
commit1e89178889741c9c4d6a61e5a01c40a8a182fa68
tree9156964427f53a09d923d8450c3bb5e6c373ff4e
parent0af711e1914ab6d88538f1fcf0146757b5608b1d
c++: ICE in value_dependent_expression_p in C++98 mode [PR94938]

Here we ICE with -std=c++98 since the newly added call to uses_template_parms
(r10-6357): we hit
26530             gcc_assert (cxx_dialect >= cxx11
26531                         || INTEGRAL_OR_ENUMERATION_TYPE_P (type));
and TYPE is a record type.  The problem is that the argument to
value_dependent_expression_p does not satisfy potential_constant_expression
which it must, as the comment explains.  I thought about fixing this in
uses_template_parms -- only call v_d_e_p if p_c_e is true, but in this
case we want to also suppress the warnings if we don't have a constant
expression.  I couldn't simply check TREE_CONSTANT as in
compute_array_index_type_loc, because then we'd stop warning in the new
Wtype-limits3.C test.

Fixed by using type_dependent_expression_p_push instead.  This means
that we won't suppress the warnings for value-dependent expressions that
aren't type-dependent, e.g. sizeof (T).  This only seems to make a
difference for -Wdiv-by-zero, now tested in Wdiv-by-zero-3.C, where I
think it's reasonable to warn.  It could make -Wtautological-compare
warn more, but that warning doesn't trigger when it gets constant arguments.
Wtype-limits4.C is a test reduced from poly-int.h and it tests a scenario
that was missing in our testsuite.

This patch also moves the warning_sentinels after the RECURs -- we mean
to use them for build_x_binary_op purposes only.

PR c++/94938
* pt.c (tsubst_copy_and_build): Call type_dependent_expression_p_push
instead of uses_template_parms.  Move the warning_sentinels after the
RECURs.

* g++.dg/warn/Wdiv-by-zero-3.C: New test.
* g++.dg/warn/Wtype-limits4.C: New test.
* g++.dg/warn/template-2.C: New test.
* g++.old-deja/g++.pt/crash10.C: Add dg-warning.
gcc/cp/ChangeLog
gcc/cp/pt.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/Wdiv-by-zero-3.C [new file with mode: 0644]
gcc/testsuite/g++.dg/warn/Wtype-limits4.C [new file with mode: 0644]
gcc/testsuite/g++.dg/warn/template-2.C [new file with mode: 0644]
gcc/testsuite/g++.old-deja/g++.pt/crash10.C