[clang] [clang] Check constexpr int->enum conversions consistently. (PR #143034)
Eli Friedman via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 9 17:08:56 PDT 2025
================
@@ -2513,6 +2513,9 @@ void testValueInRangeOfEnumerationValues() {
// expected-error at -1 {{constexpr variable 'x2' must be initialized by a constant expression}}
// expected-note at -2 {{integer value 8 is outside the valid range of values [-8, 7] for the enumeration type 'E1'}}
E1 x2b = static_cast<E1>(8); // ok, not a constant expression context
+ static_assert(static_cast<E1>(8), "");
----------------
efriedma-quic wrote:
Yes. The static_assert case wasn't emitting an error because of the `Info.EvalMode == EvalInfo::EM_ConstantExpression` check. The "neg_one_constexpr" case wasn't emitting an error because of the ConstexprVar check.
(Looking again, I guess I could have also come up with a separate testcase for the InConstantContext check, but I didn't really think too deeply about it.)
https://github.com/llvm/llvm-project/pull/143034
More information about the cfe-commits
mailing list