c++: ICE with non-constant satisfaction value [PR98644]
authorPatrick Palka <ppalka@redhat.com>
Sat, 12 Mar 2022 19:57:59 +0000 (14:57 -0500)
committerPatrick Palka <ppalka@redhat.com>
Sat, 12 Mar 2022 19:57:59 +0000 (14:57 -0500)
commitab71d3fe4b23af4c29a8d6fcf1e914fed4393e3b
treeeab2725dae7837806ea93326fa20eed2ec493e70
parent28750ac2765e808aa4f45a73c630e53575834efd
c++: ICE with non-constant satisfaction value [PR98644]

Here during satisfaction, the expression of the atomic constraint after
substitution is (int *) NON_LVALUE_EXPR <1> != 0B, which is not a C++
constant expression due to the reinterpret_cast, but TREE_CONSTANT is
set since its value is otherwise effectively constant.  We then call
maybe_constant_value on it, which proceeds via its fail-fast path to
exit early without clearing TREE_CONSTANT.  But satisfy_atom relies
on checking TREE_CONSTANT of the result of maybe_constant_value in order
to detect non-constant satisfaction.

This patch fixes this by making the fail-fast path of maybe_constant_value
clear TREE_CONSTANT in this case, like cxx_eval_outermost_constant_expr
in the normal path would have done.

PR c++/98644

gcc/cp/ChangeLog:

* constexpr.cc (mark_non_constant): Define, split out from ...
(cxx_eval_outermost_constant_expr): ... here.
(maybe_constant_value): Use it.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/concepts-pr98644.C: New test.
* g++.dg/parse/array-size2.C: Remove expected diagnostic about a
narrowing conversion.

Co-authored-by: Jason Merrill <jason@redhat.com>
gcc/cp/constexpr.cc
gcc/testsuite/g++.dg/cpp2a/concepts-pr98644.C [new file with mode: 0644]
gcc/testsuite/g++.dg/parse/array-size2.C