On the gcc-10 branch, __glibcxx_assert does not unconditionally check
the condition during constant evaluation. This means we need an explicit
additional check for std::lcm results that cannot be represented in an
unsigned result type.
libstdc++-v3/ChangeLog:
PR libstdc++/105844
* include/std/numeric (lcm): Ensure out-of-range result is
detected in constant evaluation.
* testsuite/26_numerics/lcm/105844.cc: Adjust dg-error string.
#endif
bool __overflow = __builtin_mul_overflow(__r, __n2, &__r);
+#if defined _GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED
+ if (__builtin_is_constant_evaluated())
+ if (__overflow)
+ _GLIBCXX_THROW_OR_ABORT("std::lcm result is out of range of type");
+#endif
__glibcxx_assert(!__overflow);
return __r;
}
// Similarly for unsigned, but the diagnostic is a failed assertion instead.
constexpr int e = std::lcm(500000u, 499999); // { dg-error "in 'constexpr'" }
constexpr int f = std::lcm(499999u, 500000); // { dg-error "in 'constexpr'" }
-// { dg-error "unreachable" "" { target *-*-* } 0 }
+// { dg-error "throw.* not a constant expression" "" { target *-*-* } 0 }
// { dg-prune-output "in 'constexpr' expansion" }