c++: only cache constexpr calls that are constant exprs
commitc7ac1de5f5c561b2d90c084a638c232d322d54e6
authorJason Merrill <jason@redhat.com>
Thu, 13 Jul 2023 21:48:05 +0000 (13 17:48 -0400)
committerJason Merrill <jason@redhat.com>
Mon, 17 Jul 2023 21:19:30 +0000 (17 17:19 -0400)
treed5b323908cf927886e5536cbcd58ccae0dc1224a
parentc5e9927b95debc692374a2aede21856eb94217ae
c++: only cache constexpr calls that are constant exprs

In reviewing Nathaniel's patch for PR70331, it occurred to me that instead
of looking for various specific problematic things in the result of a
constexpr call to decide whether to cache it, we should use
reduced_constant_expression_p.

The change to that function is to avoid crashing on uninitialized objects of
non-class type.

In a trial version of this patch I checked to see what cases this stopped
caching; most were instances of partially-initialized return values, which
seem fine to not cache.  Some were returning pointers to expiring local
variables, which we definitely want not to cache.  And one was bit-cast3.C,
which will be handled in a follow-up patch.

gcc/cp/ChangeLog:

* constexpr.cc (cxx_eval_call_expression): Only cache
reduced_constant_expression_p results.
(reduced_constant_expression_p): Handle CONSTRUCTOR of scalar type.
(cxx_eval_constant_expression): Fold vectors here.
(cxx_eval_bare_aggregate): Not here.
gcc/cp/constexpr.cc