Skip to content

Commit 8380a65

Browse files
EndilllGeorgeARM
authored andcommitted
[clang][NFC] Convert Sema::CCEKind to scoped enum
1 parent 1074dad commit 8380a65

10 files changed

+44
-47
lines changed

clang/include/clang/Sema/Sema.h

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,22 @@ enum class OverloadKind {
818818
NonFunction
819819
};
820820

821+
/// Contexts in which a converted constant expression is required.
822+
enum class CCEKind {
823+
CaseValue, ///< Expression in a case label.
824+
Enumerator, ///< Enumerator value with fixed underlying type.
825+
TemplateArg, ///< Value of a non-type template parameter.
826+
TempArgStrict, ///< As above, but applies strict template checking
827+
///< rules.
828+
ArrayBound, ///< Array bound in array declarator or new-expression.
829+
ExplicitBool, ///< Condition in an explicit(bool) specifier.
830+
Noexcept, ///< Condition in a noexcept(bool) specifier.
831+
StaticAssertMessageSize, ///< Call to size() in a static assert
832+
///< message.
833+
StaticAssertMessageData, ///< Call to data() in a static assert
834+
///< message.
835+
};
836+
821837
/// Sema - This implements semantic analysis and AST building for C.
822838
/// \nosubgrouping
823839
class Sema final : public SemaBase {
@@ -10218,22 +10234,6 @@ class Sema final : public SemaBase {
1021810234
/// Returns a valid but null ExprResult if no conversion sequence exists.
1021910235
ExprResult PerformContextuallyConvertToObjCPointer(Expr *From);
1022010236

10221-
/// Contexts in which a converted constant expression is required.
10222-
enum CCEKind {
10223-
CCEK_CaseValue, ///< Expression in a case label.
10224-
CCEK_Enumerator, ///< Enumerator value with fixed underlying type.
10225-
CCEK_TemplateArg, ///< Value of a non-type template parameter.
10226-
CCEK_TempArgStrict, ///< As above, but applies strict template checking
10227-
///< rules.
10228-
CCEK_ArrayBound, ///< Array bound in array declarator or new-expression.
10229-
CCEK_ExplicitBool, ///< Condition in an explicit(bool) specifier.
10230-
CCEK_Noexcept, ///< Condition in a noexcept(bool) specifier.
10231-
CCEK_StaticAssertMessageSize, ///< Call to size() in a static assert
10232-
///< message.
10233-
CCEK_StaticAssertMessageData, ///< Call to data() in a static assert
10234-
///< message.
10235-
};
10236-
1023710237
ExprResult BuildConvertedConstantExpression(Expr *From, QualType T,
1023810238
CCEKind CCE,
1023910239
NamedDecl *Dest = nullptr);

clang/lib/Sema/SemaDecl.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19844,9 +19844,8 @@ EnumConstantDecl *Sema::CheckEnumConstant(EnumDecl *Enum,
1984419844
// constant-expression in the enumerator-definition shall be a converted
1984519845
// constant expression of the underlying type.
1984619846
EltTy = Enum->getIntegerType();
19847-
ExprResult Converted =
19848-
CheckConvertedConstantExpression(Val, EltTy, EnumVal,
19849-
CCEK_Enumerator);
19847+
ExprResult Converted = CheckConvertedConstantExpression(
19848+
Val, EltTy, EnumVal, CCEKind::Enumerator);
1985019849
if (Converted.isInvalid())
1985119850
Val = nullptr;
1985219851
else

clang/lib/Sema/SemaDeclCXX.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14012,7 +14012,7 @@ void SpecialMemberExceptionSpecInfo::visitSubobjectCall(
1401214012
bool Sema::tryResolveExplicitSpecifier(ExplicitSpecifier &ExplicitSpec) {
1401314013
llvm::APSInt Result;
1401414014
ExprResult Converted = CheckConvertedConstantExpression(
14015-
ExplicitSpec.getExpr(), Context.BoolTy, Result, CCEK_ExplicitBool);
14015+
ExplicitSpec.getExpr(), Context.BoolTy, Result, CCEKind::ExplicitBool);
1401614016
ExplicitSpec.setExpr(Converted.get());
1401714017
if (Converted.isUsable() && !Converted.get()->isValueDependent()) {
1401814018
ExplicitSpec.setKind(Result.getBoolValue()
@@ -17773,7 +17773,7 @@ static bool EvaluateAsStringImpl(Sema &SemaRef, Expr *Message,
1777317773
SizeE.isInvalid()
1777417774
? ExprError()
1777517775
: SemaRef.BuildConvertedConstantExpression(
17776-
SizeE.get(), SizeT, Sema::CCEK_StaticAssertMessageSize);
17776+
SizeE.get(), SizeT, CCEKind::StaticAssertMessageSize);
1777717777
if (EvaluatedSize.isInvalid()) {
1777817778
SemaRef.Diag(Loc, diag::err_user_defined_msg_invalid_mem_fn_ret_ty)
1777917779
<< EvalContext << /*size*/ 0;
@@ -17784,7 +17784,7 @@ static bool EvaluateAsStringImpl(Sema &SemaRef, Expr *Message,
1778417784
DataE.isInvalid()
1778517785
? ExprError()
1778617786
: SemaRef.BuildConvertedConstantExpression(
17787-
DataE.get(), ConstCharPtr, Sema::CCEK_StaticAssertMessageData);
17787+
DataE.get(), ConstCharPtr, CCEKind::StaticAssertMessageData);
1778817788
if (EvaluatedData.isInvalid()) {
1778917789
SemaRef.Diag(Loc, diag::err_user_defined_msg_invalid_mem_fn_ret_ty)
1779017790
<< EvalContext << /*data*/ 1;

clang/lib/Sema/SemaExceptionSpec.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ ExprResult Sema::ActOnNoexceptSpec(Expr *NoexceptExpr,
8989

9090
llvm::APSInt Result;
9191
ExprResult Converted = CheckConvertedConstantExpression(
92-
NoexceptExpr, Context.BoolTy, Result, CCEK_Noexcept);
92+
NoexceptExpr, Context.BoolTy, Result, CCEKind::Noexcept);
9393

9494
if (Converted.isInvalid()) {
9595
EST = EST_NoexceptFalse;

clang/lib/Sema/SemaExprCXX.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2055,10 +2055,10 @@ Sema::ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal,
20552055
// shall be a converted constant expression (5.19) of type std::size_t
20562056
// and shall evaluate to a strictly positive value.
20572057
llvm::APSInt Value(Context.getIntWidth(Context.getSizeType()));
2058-
Array.NumElts
2059-
= CheckConvertedConstantExpression(NumElts, Context.getSizeType(), Value,
2060-
CCEK_ArrayBound)
2061-
.get();
2058+
Array.NumElts =
2059+
CheckConvertedConstantExpression(NumElts, Context.getSizeType(),
2060+
Value, CCEKind::ArrayBound)
2061+
.get();
20622062
} else {
20632063
Array.NumElts = VerifyIntegerConstantExpression(
20642064
NumElts, nullptr, diag::err_new_array_nonconst,

clang/lib/Sema/SemaOverload.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6212,11 +6212,10 @@ static bool CheckConvertedConstantConversions(Sema &S,
62126212
/// converted constant expression of type T, perform the conversion but
62136213
/// does not evaluate the expression
62146214
static ExprResult BuildConvertedConstantExpression(Sema &S, Expr *From,
6215-
QualType T,
6216-
Sema::CCEKind CCE,
6215+
QualType T, CCEKind CCE,
62176216
NamedDecl *Dest,
62186217
APValue &PreNarrowingValue) {
6219-
assert((S.getLangOpts().CPlusPlus11 || CCE == Sema::CCEK_TempArgStrict) &&
6218+
assert((S.getLangOpts().CPlusPlus11 || CCE == CCEKind::TempArgStrict) &&
62206219
"converted constant expression outside C++11 or TTP matching");
62216220

62226221
if (checkPlaceholderForOverload(S, From))
@@ -6228,7 +6227,7 @@ static ExprResult BuildConvertedConstantExpression(Sema &S, Expr *From,
62286227
// expression is a constant expression and the implicit conversion
62296228
// sequence contains only [... list of conversions ...].
62306229
ImplicitConversionSequence ICS =
6231-
(CCE == Sema::CCEK_ExplicitBool || CCE == Sema::CCEK_Noexcept)
6230+
(CCE == CCEKind::ExplicitBool || CCE == CCEKind::Noexcept)
62326231
? TryContextuallyConvertToBool(S, From)
62336232
: TryCopyInitialization(S, From, T,
62346233
/*SuppressUserConversions=*/false,
@@ -6287,7 +6286,7 @@ static ExprResult BuildConvertedConstantExpression(Sema &S, Expr *From,
62876286
// class type.
62886287
ExprResult Result;
62896288
bool IsTemplateArgument =
6290-
CCE == Sema::CCEK_TemplateArg || CCE == Sema::CCEK_TempArgStrict;
6289+
CCE == CCEKind::TemplateArg || CCE == CCEKind::TempArgStrict;
62916290
if (T->isRecordType()) {
62926291
assert(IsTemplateArgument &&
62936292
"unexpected class type converted constant expr");
@@ -6322,7 +6321,7 @@ static ExprResult BuildConvertedConstantExpression(Sema &S, Expr *From,
63226321
break;
63236322

63246323
case NK_Constant_Narrowing:
6325-
if (CCE == Sema::CCEK_ArrayBound &&
6324+
if (CCE == CCEKind::ArrayBound &&
63266325
PreNarrowingType->isIntegralOrEnumerationType() &&
63276326
PreNarrowingValue.isInt()) {
63286327
// Don't diagnose array bound narrowing here; we produce more precise
@@ -6340,7 +6339,7 @@ static ExprResult BuildConvertedConstantExpression(Sema &S, Expr *From,
63406339
// value-dependent so we can't tell whether it's actually narrowing.
63416340
// For matching the parameters of a TTP, the conversion is ill-formed
63426341
// if it may narrow.
6343-
if (CCE != Sema::CCEK_TempArgStrict)
6342+
if (CCE != CCEKind::TempArgStrict)
63446343
break;
63456344
[[fallthrough]];
63466345
case NK_Type_Narrowing:
@@ -6361,8 +6360,7 @@ static ExprResult BuildConvertedConstantExpression(Sema &S, Expr *From,
63616360
/// the converted expression, per C++11 [expr.const]p3.
63626361
static ExprResult CheckConvertedConstantExpression(Sema &S, Expr *From,
63636362
QualType T, APValue &Value,
6364-
Sema::CCEKind CCE,
6365-
bool RequireInt,
6363+
CCEKind CCE, bool RequireInt,
63666364
NamedDecl *Dest) {
63676365

63686366
APValue PreNarrowingValue;
@@ -6406,7 +6404,7 @@ ExprResult Sema::CheckConvertedConstantExpression(Expr *From, QualType T,
64066404

64076405
ExprResult
64086406
Sema::EvaluateConvertedConstantExpression(Expr *E, QualType T, APValue &Value,
6409-
Sema::CCEKind CCE, bool RequireInt,
6407+
CCEKind CCE, bool RequireInt,
64106408
const APValue &PreNarrowingValue) {
64116409

64126410
ExprResult Result = E;
@@ -6415,12 +6413,12 @@ Sema::EvaluateConvertedConstantExpression(Expr *E, QualType T, APValue &Value,
64156413
Expr::EvalResult Eval;
64166414
Eval.Diag = &Notes;
64176415

6418-
assert(CCE != Sema::CCEK_TempArgStrict && "unnexpected CCE Kind");
6416+
assert(CCE != CCEKind::TempArgStrict && "unnexpected CCE Kind");
64196417

64206418
ConstantExprKind Kind;
6421-
if (CCE == Sema::CCEK_TemplateArg && T->isRecordType())
6419+
if (CCE == CCEKind::TemplateArg && T->isRecordType())
64226420
Kind = ConstantExprKind::ClassTemplateArgument;
6423-
else if (CCE == Sema::CCEK_TemplateArg)
6421+
else if (CCE == CCEKind::TemplateArg)
64246422
Kind = ConstantExprKind::NonClassTemplateArgument;
64256423
else
64266424
Kind = ConstantExprKind::Normal;

clang/lib/Sema/SemaStmt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ Sema::ActOnCaseExpr(SourceLocation CaseLoc, ExprResult Val) {
521521
// constant expression of the promoted type of the switch condition.
522522
llvm::APSInt TempVal;
523523
return CheckConvertedConstantExpression(E, CondType, TempVal,
524-
CCEK_CaseValue);
524+
CCEKind::CaseValue);
525525
}
526526

527527
ExprResult ER = E;

clang/lib/Sema/SemaTemplate.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6962,7 +6962,7 @@ ExprResult Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
69626962
if (IsConvertedConstantExpression) {
69636963
ArgResult = BuildConvertedConstantExpression(
69646964
DeductionArg, ParamType,
6965-
StrictCheck ? CCEK_TempArgStrict : CCEK_TemplateArg, Param);
6965+
StrictCheck ? CCEKind::TempArgStrict : CCEKind::TemplateArg, Param);
69666966
assert(!ArgResult.isUnset());
69676967
if (ArgResult.isInvalid()) {
69686968
NoteTemplateParameterLocation(*Param);
@@ -6984,7 +6984,7 @@ ExprResult Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
69846984

69856985
APValue PreNarrowingValue;
69866986
ArgResult = EvaluateConvertedConstantExpression(
6987-
ArgResult.get(), ParamType, Value, CCEK_TemplateArg, /*RequireInt=*/
6987+
ArgResult.get(), ParamType, Value, CCEKind::TemplateArg, /*RequireInt=*/
69886988
false, PreNarrowingValue);
69896989
if (ArgResult.isInvalid())
69906990
return ExprError();
@@ -7083,7 +7083,7 @@ ExprResult Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
70837083
// template-parameter; or
70847084
llvm::APSInt Value;
70857085
ExprResult ArgResult = CheckConvertedConstantExpression(
7086-
DeductionArg, ParamType, Value, CCEK_TemplateArg);
7086+
DeductionArg, ParamType, Value, CCEKind::TemplateArg);
70877087
if (ArgResult.isInvalid())
70887088
return ExprError();
70897089
setDeductionArg(ArgResult.get());

clang/lib/Sema/SemaTemplateVariadic.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1229,7 +1229,7 @@ ExprResult Sema::BuildPackIndexingExpr(Expr *PackExpression,
12291229
llvm::APSInt Value(Context.getIntWidth(Context.getSizeType()));
12301230

12311231
ExprResult Res = CheckConvertedConstantExpression(
1232-
IndexExpr, Context.getSizeType(), Value, CCEK_ArrayBound);
1232+
IndexExpr, Context.getSizeType(), Value, CCEKind::ArrayBound);
12331233
if (!Res.isUsable())
12341234
return ExprError();
12351235
Index = Value.getExtValue();

clang/lib/Sema/SemaType.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1993,7 +1993,7 @@ static ExprResult checkArraySize(Sema &S, Expr *&ArraySize,
19931993
// the converted constant expression rules (to properly convert the source)
19941994
// when the source expression is of class type.
19951995
return S.CheckConvertedConstantExpression(
1996-
ArraySize, S.Context.getSizeType(), SizeVal, Sema::CCEK_ArrayBound);
1996+
ArraySize, S.Context.getSizeType(), SizeVal, CCEKind::ArrayBound);
19971997
}
19981998

19991999
// 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,
97639763
!IndexExpr->isTypeDependent()) {
97649764
llvm::APSInt Value(Context.getIntWidth(Context.getSizeType()));
97659765
ExprResult Res = CheckConvertedConstantExpression(
9766-
IndexExpr, Context.getSizeType(), Value, CCEK_ArrayBound);
9766+
IndexExpr, Context.getSizeType(), Value, CCEKind::ArrayBound);
97679767
if (!Res.isUsable())
97689768
return QualType();
97699769
IndexExpr = Res.get();

0 commit comments

Comments
 (0)