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.
{
/* 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. */
--- /dev/null
+// PR c++/105931
+// { dg-do compile { target c++11 } }
+// A version of decltype82.C where N is unsigned.
+
+template<unsigned N>
+void f() {
+ using ty1 = decltype((5 % N) == 0);
+ using ty2 = decltype((5 / N) == 0);
+}
+
+template void f<0>();