c++: Prevent bogus -Wtype-limits warning with NTTP [PR100161]
authorMarek Polacek <polacek@redhat.com>
Wed, 21 Apr 2021 00:24:09 +0000 (20:24 -0400)
committerMarek Polacek <polacek@redhat.com>
Thu, 22 Apr 2021 21:35:38 +0000 (17:35 -0400)
commit244dfb95119106e9267f37583caac565c39eb0ec
tree157a684ffc69a6222e8e7d96917b11dc3942aa37
parent3275f2e2af24541f55462c23af4c6530ac12c5e2
c++: Prevent bogus -Wtype-limits warning with NTTP [PR100161]

Recently, we made sure that we never call value_dependent_expression_p
on an expression that isn't potential_constant_expression.  That caused
this bogus warning with a non-type template parameter, something that
users don't want to see.

The problem is that in tsubst_copy_and_build/LE_EXPR 't' is "i < n",
which, due to 'i', is not p_c_e, therefore we call t_d_e_p.  But the
type of 'n' isn't dependent, so we think the whole 't' expression is
not dependent.  It seems we need to test both op0 and op1 separately
to suppress this warning.

gcc/cp/ChangeLog:

PR c++/100161
* pt.c (tsubst_copy_and_build) <case PLUS_EXPR>: Test op0 and
op1 separately for value- or type-dependence.

gcc/testsuite/ChangeLog:

PR c++/100161
* g++.dg/warn/Wtype-limits6.C: New test.
gcc/cp/pt.c
gcc/testsuite/g++.dg/warn/Wtype-limits6.C [new file with mode: 0644]