aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/expr.cc
diff options
context:
space:
mode:
authorPatrick Palka <ppalka@redhat.com>2022-06-23 16:36:43 -0400
committerPatrick Palka <ppalka@redhat.com>2022-06-23 16:36:43 -0400
commitb00b95198e6720eb23a2618870d67800f6180fdd (patch)
tree7a13650a79c41666833341dabc72dfacd7a90700 /gcc/cp/expr.cc
parent01aff2ba18a654324957af446a3065db489c0f14 (diff)
downloadgcc-b00b95198e6720eb23a2618870d67800f6180fdd.zip
gcc-b00b95198e6720eb23a2618870d67800f6180fdd.tar.gz
gcc-b00b95198e6720eb23a2618870d67800f6180fdd.tar.bz2
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.
Diffstat (limited to 'gcc/cp/expr.cc')
-rw-r--r--gcc/cp/expr.cc5
1 files changed, 5 insertions, 0 deletions
diff --git a/gcc/cp/expr.cc b/gcc/cp/expr.cc
index 31fe098..56fc11f 100644
--- a/gcc/cp/expr.cc
+++ b/gcc/cp/expr.cc
@@ -397,6 +397,11 @@ fold_for_warn (tree x)
{
/* C++ implementation. */
+ if (cp_unevaluated_operand)
+ /* In an unevaluated context we don't care about the reduced value
+ of an expression, so neither should any warnings. */
+ return x;
+
/* Prevent warning-dependent constexpr evaluation from changing
DECL_UID (which breaks -fcompare-debug) and from instantiating
templates. */