[clang] cf2f13a - [clang][NFC] Convert `Sema::CCEKind` to scoped enum
Vlad Serebrennikov via cfe-commits
cfe-commits at lists.llvm.org
Fri May 2 04:01:47 PDT 2025
Author: Vlad Serebrennikov
Date: 2025-05-02T14:01:40+03:00
New Revision: cf2f13a867fb86b5c7ce33df8a569477dce71f4f
URL: https://github.com/llvm/llvm-project/commit/cf2f13a867fb86b5c7ce33df8a569477dce71f4f
DIFF: https://github.com/llvm/llvm-project/commit/cf2f13a867fb86b5c7ce33df8a569477dce71f4f.diff
LOG: [clang][NFC] Convert `Sema::CCEKind` to scoped enum
Added:
Modified:
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaExceptionSpec.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaOverload.cpp
clang/lib/Sema/SemaStmt.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/lib/Sema/SemaTemplateVariadic.cpp
clang/lib/Sema/SemaType.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 41582096f7dc1..dbb4a954cfb2a 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -818,6 +818,22 @@ enum class OverloadKind {
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 @@ class Sema final : public SemaBase {
/// 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 829207b4cf910..e1d7fc6d60f3c 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -19844,9 +19844,8 @@ EnumConstantDecl *Sema::CheckEnumConstant(EnumDecl *Enum,
// 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 6e6e39acc1cb3..22e21524c54be 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -14012,7 +14012,7 @@ void SpecialMemberExceptionSpecInfo::visitSubobjectCall(
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 @@ static bool EvaluateAsStringImpl(Sema &SemaRef, Expr *Message,
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 @@ static bool EvaluateAsStringImpl(Sema &SemaRef, Expr *Message,
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 f358d8342e2f3..aaa2bb22565e4 100644
--- a/clang/lib/Sema/SemaExceptionSpec.cpp
+++ b/clang/lib/Sema/SemaExceptionSpec.cpp
@@ -89,7 +89,7 @@ ExprResult Sema::ActOnNoexceptSpec(Expr *NoexceptExpr,
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 87a840d37e1d9..9ff4bc6c7e38f 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -2055,10 +2055,10 @@ Sema::ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal,
// 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 ead87ab8236e9..45415b71ee65c 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -6212,11 +6212,10 @@ static bool CheckConvertedConstantConversions(Sema &S,
/// 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 @@ static ExprResult BuildConvertedConstantExpression(Sema &S, Expr *From,
// 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 @@ static ExprResult BuildConvertedConstantExpression(Sema &S, Expr *From,
// 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 @@ static ExprResult BuildConvertedConstantExpression(Sema &S, Expr *From,
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 @@ static ExprResult BuildConvertedConstantExpression(Sema &S, Expr *From,
// 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 @@ static ExprResult BuildConvertedConstantExpression(Sema &S, Expr *From,
/// 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::CheckConvertedConstantExpression(Expr *From, QualType T,
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 @@ Sema::EvaluateConvertedConstantExpression(Expr *E, QualType T, APValue &Value,
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 3ca9993ae65cc..e8c1f8490342a 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -521,7 +521,7 @@ Sema::ActOnCaseExpr(SourceLocation CaseLoc, ExprResult Val) {
// 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 a367349d943bf..95c7b6f25ddc6 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -6962,7 +6962,7 @@ ExprResult Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
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 @@ ExprResult Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
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 @@ ExprResult Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
// 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 f876312490208..5f0e968ff18c4 100644
--- a/clang/lib/Sema/SemaTemplateVariadic.cpp
+++ b/clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -1229,7 +1229,7 @@ ExprResult Sema::BuildPackIndexingExpr(Expr *PackExpression,
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 556530c3fe13d..c1adf35a22270 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -1993,7 +1993,7 @@ static ExprResult checkArraySize(Sema &S, Expr *&ArraySize,
// 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 @@ QualType Sema::BuildPackIndexingType(QualType Pattern, Expr *IndexExpr,
!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();
More information about the cfe-commits
mailing list