c++: constexpr folding in unevaluated context [PR105931]
authorPatrick Palka <ppalka@redhat.com>
Thu, 23 Jun 2022 20:36:43 +0000 (16:36 -0400)
committerPatrick Palka <ppalka@redhat.com>
Fri, 24 Jun 2022 02:58:24 +0000 (22:58 -0400)
commit5cf4746c3d4e80a360bd15b31136339d6812597e
tree0b3fcb5ae81482f1995613e4a0e3f7789a215c98
parentc822723646bd7defb3db4f96aa513384b65d8e31
c++: constexpr folding in unevaluated context [PR105931]

Changing the type of N from int to unsigned in decltype82.C (from
r13-986-g0ecb6b906f215e) reveals another spot where we perform constexpr
evaluation in an unevaluated context for sake of warnings, this time
from the call to shorten_compare in cp_build_binary_op, which calls
fold_for_warn.

We could (and probably should) suppress the shorten_compare warnings
when in an unevaluated context, but there's probably other callers of
fold_for_warn that are similarly affected.  So this patch takes the
approach of directly suppressing fold_for_warn when in an unevaluated
context.

PR c++/105931

gcc/cp/ChangeLog:

* expr.cc (fold_for_warn): Don't fold when in an unevaluated
context.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/decltype82a.C: New test.

(cherry picked from commit b00b95198e6720eb23a2618870d67800f6180fdd)
gcc/cp/expr.cc
gcc/testsuite/g++.dg/cpp0x/decltype82a.C [new file with mode: 0644]