[clang][NFC] Convert `Sema::CCEKind` to scoped enum
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 4158209..dbb4a95 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h
@@ -818,6 +818,22 @@ NonFunction }; +/// Contexts in which a converted constant expression is required. +enum class CCEKind { + CaseValue, ///< Expression in a case label. + Enumerator, ///< Enumerator value with fixed underlying type. + TemplateArg, ///< Value of a non-type template parameter. + TempArgStrict, ///< As above, but applies strict template checking + ///< rules. + ArrayBound, ///< Array bound in array declarator or new-expression. + ExplicitBool, ///< Condition in an explicit(bool) specifier. + Noexcept, ///< Condition in a noexcept(bool) specifier. + StaticAssertMessageSize, ///< Call to size() in a static assert + ///< message. + StaticAssertMessageData, ///< Call to data() in a static assert + ///< message. +}; + /// Sema - This implements semantic analysis and AST building for C. /// \nosubgrouping class Sema final : public SemaBase { @@ -10218,22 +10234,6 @@ /// Returns a valid but null ExprResult if no conversion sequence exists. ExprResult PerformContextuallyConvertToObjCPointer(Expr *From); - /// Contexts in which a converted constant expression is required. - enum CCEKind { - CCEK_CaseValue, ///< Expression in a case label. - CCEK_Enumerator, ///< Enumerator value with fixed underlying type. - CCEK_TemplateArg, ///< Value of a non-type template parameter. - CCEK_TempArgStrict, ///< As above, but applies strict template checking - ///< rules. - CCEK_ArrayBound, ///< Array bound in array declarator or new-expression. - CCEK_ExplicitBool, ///< Condition in an explicit(bool) specifier. - CCEK_Noexcept, ///< Condition in a noexcept(bool) specifier. - CCEK_StaticAssertMessageSize, ///< Call to size() in a static assert - ///< message. - CCEK_StaticAssertMessageData, ///< Call to data() in a static assert - ///< message. - }; - ExprResult BuildConvertedConstantExpression(Expr *From, QualType T, CCEKind CCE, NamedDecl *Dest = nullptr);
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 829207b..e1d7fc6 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp
@@ -19844,9 +19844,8 @@ // constant-expression in the enumerator-definition shall be a converted // constant expression of the underlying type. EltTy = Enum->getIntegerType(); - ExprResult Converted = - CheckConvertedConstantExpression(Val, EltTy, EnumVal, - CCEK_Enumerator); + ExprResult Converted = CheckConvertedConstantExpression( + Val, EltTy, EnumVal, CCEKind::Enumerator); if (Converted.isInvalid()) Val = nullptr; else
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 6e6e39a..22e2152 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -14012,7 +14012,7 @@ bool Sema::tryResolveExplicitSpecifier(ExplicitSpecifier &ExplicitSpec) { llvm::APSInt Result; ExprResult Converted = CheckConvertedConstantExpression( - ExplicitSpec.getExpr(), Context.BoolTy, Result, CCEK_ExplicitBool); + ExplicitSpec.getExpr(), Context.BoolTy, Result, CCEKind::ExplicitBool); ExplicitSpec.setExpr(Converted.get()); if (Converted.isUsable() && !Converted.get()->isValueDependent()) { ExplicitSpec.setKind(Result.getBoolValue() @@ -17773,7 +17773,7 @@ SizeE.isInvalid() ? ExprError() : SemaRef.BuildConvertedConstantExpression( - SizeE.get(), SizeT, Sema::CCEK_StaticAssertMessageSize); + SizeE.get(), SizeT, CCEKind::StaticAssertMessageSize); if (EvaluatedSize.isInvalid()) { SemaRef.Diag(Loc, diag::err_user_defined_msg_invalid_mem_fn_ret_ty) << EvalContext << /*size*/ 0; @@ -17784,7 +17784,7 @@ DataE.isInvalid() ? ExprError() : SemaRef.BuildConvertedConstantExpression( - DataE.get(), ConstCharPtr, Sema::CCEK_StaticAssertMessageData); + DataE.get(), ConstCharPtr, CCEKind::StaticAssertMessageData); if (EvaluatedData.isInvalid()) { SemaRef.Diag(Loc, diag::err_user_defined_msg_invalid_mem_fn_ret_ty) << EvalContext << /*data*/ 1;
diff --git a/clang/lib/Sema/SemaExceptionSpec.cpp b/clang/lib/Sema/SemaExceptionSpec.cpp index f358d83..aaa2bb2 100644 --- a/clang/lib/Sema/SemaExceptionSpec.cpp +++ b/clang/lib/Sema/SemaExceptionSpec.cpp
@@ -89,7 +89,7 @@ llvm::APSInt Result; ExprResult Converted = CheckConvertedConstantExpression( - NoexceptExpr, Context.BoolTy, Result, CCEK_Noexcept); + NoexceptExpr, Context.BoolTy, Result, CCEKind::Noexcept); if (Converted.isInvalid()) { EST = EST_NoexceptFalse;
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index 87a840d..9ff4bc6 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -2055,10 +2055,10 @@ // shall be a converted constant expression (5.19) of type std::size_t // and shall evaluate to a strictly positive value. llvm::APSInt Value(Context.getIntWidth(Context.getSizeType())); - Array.NumElts - = CheckConvertedConstantExpression(NumElts, Context.getSizeType(), Value, - CCEK_ArrayBound) - .get(); + Array.NumElts = + CheckConvertedConstantExpression(NumElts, Context.getSizeType(), + Value, CCEKind::ArrayBound) + .get(); } else { Array.NumElts = VerifyIntegerConstantExpression( NumElts, nullptr, diag::err_new_array_nonconst,
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp index ead87ab..45415b7 100644 --- a/clang/lib/Sema/SemaOverload.cpp +++ b/clang/lib/Sema/SemaOverload.cpp
@@ -6212,11 +6212,10 @@ /// converted constant expression of type T, perform the conversion but /// does not evaluate the expression static ExprResult BuildConvertedConstantExpression(Sema &S, Expr *From, - QualType T, - Sema::CCEKind CCE, + QualType T, CCEKind CCE, NamedDecl *Dest, APValue &PreNarrowingValue) { - assert((S.getLangOpts().CPlusPlus11 || CCE == Sema::CCEK_TempArgStrict) && + assert((S.getLangOpts().CPlusPlus11 || CCE == CCEKind::TempArgStrict) && "converted constant expression outside C++11 or TTP matching"); if (checkPlaceholderForOverload(S, From)) @@ -6228,7 +6227,7 @@ // expression is a constant expression and the implicit conversion // sequence contains only [... list of conversions ...]. ImplicitConversionSequence ICS = - (CCE == Sema::CCEK_ExplicitBool || CCE == Sema::CCEK_Noexcept) + (CCE == CCEKind::ExplicitBool || CCE == CCEKind::Noexcept) ? TryContextuallyConvertToBool(S, From) : TryCopyInitialization(S, From, T, /*SuppressUserConversions=*/false, @@ -6287,7 +6286,7 @@ // class type. ExprResult Result; bool IsTemplateArgument = - CCE == Sema::CCEK_TemplateArg || CCE == Sema::CCEK_TempArgStrict; + CCE == CCEKind::TemplateArg || CCE == CCEKind::TempArgStrict; if (T->isRecordType()) { assert(IsTemplateArgument && "unexpected class type converted constant expr"); @@ -6322,7 +6321,7 @@ break; case NK_Constant_Narrowing: - if (CCE == Sema::CCEK_ArrayBound && + if (CCE == CCEKind::ArrayBound && PreNarrowingType->isIntegralOrEnumerationType() && PreNarrowingValue.isInt()) { // Don't diagnose array bound narrowing here; we produce more precise @@ -6340,7 +6339,7 @@ // value-dependent so we can't tell whether it's actually narrowing. // For matching the parameters of a TTP, the conversion is ill-formed // if it may narrow. - if (CCE != Sema::CCEK_TempArgStrict) + if (CCE != CCEKind::TempArgStrict) break; [[fallthrough]]; case NK_Type_Narrowing: @@ -6361,8 +6360,7 @@ /// the converted expression, per C++11 [expr.const]p3. static ExprResult CheckConvertedConstantExpression(Sema &S, Expr *From, QualType T, APValue &Value, - Sema::CCEKind CCE, - bool RequireInt, + CCEKind CCE, bool RequireInt, NamedDecl *Dest) { APValue PreNarrowingValue; @@ -6406,7 +6404,7 @@ ExprResult Sema::EvaluateConvertedConstantExpression(Expr *E, QualType T, APValue &Value, - Sema::CCEKind CCE, bool RequireInt, + CCEKind CCE, bool RequireInt, const APValue &PreNarrowingValue) { ExprResult Result = E; @@ -6415,12 +6413,12 @@ Expr::EvalResult Eval; Eval.Diag = &Notes; - assert(CCE != Sema::CCEK_TempArgStrict && "unnexpected CCE Kind"); + assert(CCE != CCEKind::TempArgStrict && "unnexpected CCE Kind"); ConstantExprKind Kind; - if (CCE == Sema::CCEK_TemplateArg && T->isRecordType()) + if (CCE == CCEKind::TemplateArg && T->isRecordType()) Kind = ConstantExprKind::ClassTemplateArgument; - else if (CCE == Sema::CCEK_TemplateArg) + else if (CCE == CCEKind::TemplateArg) Kind = ConstantExprKind::NonClassTemplateArgument; else Kind = ConstantExprKind::Normal;
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index 3ca9993..e8c1f84 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp
@@ -521,7 +521,7 @@ // constant expression of the promoted type of the switch condition. llvm::APSInt TempVal; return CheckConvertedConstantExpression(E, CondType, TempVal, - CCEK_CaseValue); + CCEKind::CaseValue); } ExprResult ER = E;
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index a367349..95c7b6f 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -6962,7 +6962,7 @@ if (IsConvertedConstantExpression) { ArgResult = BuildConvertedConstantExpression( DeductionArg, ParamType, - StrictCheck ? CCEK_TempArgStrict : CCEK_TemplateArg, Param); + StrictCheck ? CCEKind::TempArgStrict : CCEKind::TemplateArg, Param); assert(!ArgResult.isUnset()); if (ArgResult.isInvalid()) { NoteTemplateParameterLocation(*Param); @@ -6984,7 +6984,7 @@ APValue PreNarrowingValue; ArgResult = EvaluateConvertedConstantExpression( - ArgResult.get(), ParamType, Value, CCEK_TemplateArg, /*RequireInt=*/ + ArgResult.get(), ParamType, Value, CCEKind::TemplateArg, /*RequireInt=*/ false, PreNarrowingValue); if (ArgResult.isInvalid()) return ExprError(); @@ -7083,7 +7083,7 @@ // template-parameter; or llvm::APSInt Value; ExprResult ArgResult = CheckConvertedConstantExpression( - DeductionArg, ParamType, Value, CCEK_TemplateArg); + DeductionArg, ParamType, Value, CCEKind::TemplateArg); if (ArgResult.isInvalid()) return ExprError(); setDeductionArg(ArgResult.get());
diff --git a/clang/lib/Sema/SemaTemplateVariadic.cpp b/clang/lib/Sema/SemaTemplateVariadic.cpp index f876312..5f0e968 100644 --- a/clang/lib/Sema/SemaTemplateVariadic.cpp +++ b/clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -1229,7 +1229,7 @@ llvm::APSInt Value(Context.getIntWidth(Context.getSizeType())); ExprResult Res = CheckConvertedConstantExpression( - IndexExpr, Context.getSizeType(), Value, CCEK_ArrayBound); + IndexExpr, Context.getSizeType(), Value, CCEKind::ArrayBound); if (!Res.isUsable()) return ExprError(); Index = Value.getExtValue();
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index 556530c..c1adf35 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp
@@ -1993,7 +1993,7 @@ // the converted constant expression rules (to properly convert the source) // when the source expression is of class type. return S.CheckConvertedConstantExpression( - ArraySize, S.Context.getSizeType(), SizeVal, Sema::CCEK_ArrayBound); + ArraySize, S.Context.getSizeType(), SizeVal, CCEKind::ArrayBound); } // If the size is an ICE, it certainly isn't a VLA. If we're in a GNU mode @@ -9763,7 +9763,7 @@ !IndexExpr->isTypeDependent()) { llvm::APSInt Value(Context.getIntWidth(Context.getSizeType())); ExprResult Res = CheckConvertedConstantExpression( - IndexExpr, Context.getSizeType(), Value, CCEK_ArrayBound); + IndexExpr, Context.getSizeType(), Value, CCEKind::ArrayBound); if (!Res.isUsable()) return QualType(); IndexExpr = Res.get();