Skip to content

Commit 461255e

Browse files
committed
[clang][NFC] Convert Sema::AllocationFunctionScope to scoped enum
1 parent ff8060a commit 461255e

File tree

3 files changed

+40
-34
lines changed

3 files changed

+40
-34
lines changed

clang/include/clang/Sema/Sema.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,18 @@ enum class AssignConvertType {
771771
Incompatible
772772
};
773773

774+
/// The scope in which to find allocation functions.
775+
enum class AllocationFunctionScope {
776+
/// Only look for allocation functions in the global scope.
777+
Global,
778+
/// Only look for allocation functions in the scope of the
779+
/// allocated class.
780+
Class,
781+
/// Look for allocation functions in both the global scope
782+
/// and in the scope of the allocated class.
783+
Both
784+
};
785+
774786
/// Sema - This implements semantic analysis and AST building for C.
775787
/// \nosubgrouping
776788
class Sema final : public SemaBase {
@@ -8372,18 +8384,6 @@ class Sema final : public SemaBase {
83728384
bool CheckAllocatedType(QualType AllocType, SourceLocation Loc,
83738385
SourceRange R);
83748386

8375-
/// The scope in which to find allocation functions.
8376-
enum AllocationFunctionScope {
8377-
/// Only look for allocation functions in the global scope.
8378-
AFS_Global,
8379-
/// Only look for allocation functions in the scope of the
8380-
/// allocated class.
8381-
AFS_Class,
8382-
/// Look for allocation functions in both the global scope
8383-
/// and in the scope of the allocated class.
8384-
AFS_Both
8385-
};
8386-
83878387
/// Finds the overloads of operator new and delete that are appropriate
83888388
/// for the allocation.
83898389
bool FindAllocationFunctions(

clang/lib/Sema/SemaCoroutine.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,8 +1455,8 @@ bool CoroutineStmtBuilder::makeNewAndDeleteExpr() {
14551455
// allocation function.
14561456
ImplicitAllocationParameters IAP(
14571457
alignedAllocationModeFromBool(S.getLangOpts().CoroAlignedAllocation));
1458-
auto LookupAllocationFunction = [&](Sema::AllocationFunctionScope NewScope =
1459-
Sema::AFS_Both,
1458+
auto LookupAllocationFunction = [&](AllocationFunctionScope NewScope =
1459+
AllocationFunctionScope::Both,
14601460
bool WithoutPlacementArgs = false,
14611461
bool ForceNonAligned = false) {
14621462
// [dcl.fct.def.coroutine]p9
@@ -1465,21 +1465,22 @@ bool CoroutineStmtBuilder::makeNewAndDeleteExpr() {
14651465
// - If any declarations are found, ...
14661466
// - If no declarations are found in the scope of the promise type, a search
14671467
// is performed in the global scope.
1468-
if (NewScope == Sema::AFS_Both)
1469-
NewScope = PromiseContainsNew ? Sema::AFS_Class : Sema::AFS_Global;
1468+
if (NewScope == AllocationFunctionScope::Both)
1469+
NewScope = PromiseContainsNew ? AllocationFunctionScope::Class
1470+
: AllocationFunctionScope::Global;
14701471

14711472
bool ShouldUseAlignedAlloc =
14721473
!ForceNonAligned && S.getLangOpts().CoroAlignedAllocation;
14731474
IAP = ImplicitAllocationParameters(
14741475
alignedAllocationModeFromBool(ShouldUseAlignedAlloc));
14751476

14761477
FunctionDecl *UnusedResult = nullptr;
1477-
S.FindAllocationFunctions(Loc, SourceRange(), NewScope,
1478-
/*DeleteScope=*/Sema::AFS_Both, PromiseType,
1479-
/*isArray=*/false, IAP,
1480-
WithoutPlacementArgs ? MultiExprArg{}
1481-
: PlacementArgs,
1482-
OperatorNew, UnusedResult, /*Diagnose=*/false);
1478+
S.FindAllocationFunctions(
1479+
Loc, SourceRange(), NewScope,
1480+
/*DeleteScope=*/AllocationFunctionScope::Both, PromiseType,
1481+
/*isArray=*/false, IAP,
1482+
WithoutPlacementArgs ? MultiExprArg{} : PlacementArgs, OperatorNew,
1483+
UnusedResult, /*Diagnose=*/false);
14831484
assert(!OperatorNew || !OperatorNew->isTypeAwareOperatorNewOrDelete());
14841485
};
14851486

@@ -1506,7 +1507,7 @@ bool CoroutineStmtBuilder::makeNewAndDeleteExpr() {
15061507
// an argument of type std:align_val_t as the second argument.
15071508
if (!OperatorNew || (S.getLangOpts().CoroAlignedAllocation &&
15081509
!isAlignedAllocation(IAP.PassAlignment)))
1509-
LookupAllocationFunction(/*NewScope*/ Sema::AFS_Class,
1510+
LookupAllocationFunction(/*NewScope*/ AllocationFunctionScope::Class,
15101511
/*WithoutPlacementArgs*/ true);
15111512
}
15121513

@@ -1533,12 +1534,12 @@ bool CoroutineStmtBuilder::makeNewAndDeleteExpr() {
15331534
if (!OperatorNew || !isAlignedAllocation(IAP.PassAlignment)) {
15341535
FoundNonAlignedInPromise = OperatorNew;
15351536

1536-
LookupAllocationFunction(/*NewScope*/ Sema::AFS_Class,
1537+
LookupAllocationFunction(/*NewScope*/ AllocationFunctionScope::Class,
15371538
/*WithoutPlacementArgs*/ false,
15381539
/*ForceNonAligned*/ true);
15391540

15401541
if (!OperatorNew && !PlacementArgs.empty())
1541-
LookupAllocationFunction(/*NewScope*/ Sema::AFS_Class,
1542+
LookupAllocationFunction(/*NewScope*/ AllocationFunctionScope::Class,
15421543
/*WithoutPlacementArgs*/ true,
15431544
/*ForceNonAligned*/ true);
15441545
}
@@ -1554,7 +1555,7 @@ bool CoroutineStmtBuilder::makeNewAndDeleteExpr() {
15541555
return false;
15551556
PlacementArgs = {StdNoThrow};
15561557
OperatorNew = nullptr;
1557-
LookupAllocationFunction(Sema::AFS_Global);
1558+
LookupAllocationFunction(AllocationFunctionScope::Global);
15581559
}
15591560

15601561
// If we found a non-aligned allocation function in the promise_type,

clang/lib/Sema/SemaExprCXX.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2431,7 +2431,8 @@ ExprResult Sema::BuildCXXNew(SourceRange Range, bool UseGlobal,
24312431
if (CheckArgsForPlaceholders(PlacementArgs))
24322432
return ExprError();
24332433

2434-
AllocationFunctionScope Scope = UseGlobal ? AFS_Global : AFS_Both;
2434+
AllocationFunctionScope Scope = UseGlobal ? AllocationFunctionScope::Global
2435+
: AllocationFunctionScope::Both;
24352436
SourceRange AllocationParameterRange = Range;
24362437
if (PlacementLParen.isValid() && PlacementRParen.isValid())
24372438
AllocationParameterRange = SourceRange(PlacementLParen, PlacementRParen);
@@ -2906,9 +2907,11 @@ bool Sema::FindAllocationFunctions(
29062907
FunctionDecl *&OperatorDelete, bool Diagnose) {
29072908
// --- Choosing an allocation function ---
29082909
// C++ 5.3.4p8 - 14 & 18
2909-
// 1) If looking in AFS_Global scope for allocation functions, only look in
2910-
// the global scope. Else, if AFS_Class, only look in the scope of the
2911-
// allocated class. If AFS_Both, look in both.
2910+
// 1) If looking in AllocationFunctionScope::Global scope for allocation
2911+
// functions, only look in
2912+
// the global scope. Else, if AllocationFunctionScope::Class, only look in
2913+
// the scope of the allocated class. If AllocationFunctionScope::Both, look
2914+
// in both.
29122915
// 2) If an array size is given, look for operator new[], else look for
29132916
// operator new.
29142917
// 3) The first argument is always size_t. Append the arguments from the
@@ -2981,7 +2984,8 @@ bool Sema::FindAllocationFunctions(
29812984
// function's name is looked up in the global scope. Otherwise, if the
29822985
// allocated type is a class type T or array thereof, the allocation
29832986
// function's name is looked up in the scope of T.
2984-
if (AllocElemType->isRecordType() && NewScope != AFS_Global)
2987+
if (AllocElemType->isRecordType() &&
2988+
NewScope != AllocationFunctionScope::Global)
29852989
LookupQualifiedName(R, AllocElemType->getAsCXXRecordDecl());
29862990

29872991
// We can see ambiguity here if the allocation function is found in
@@ -2993,7 +2997,7 @@ bool Sema::FindAllocationFunctions(
29932997
// a class type, the allocation function's name is looked up in the
29942998
// global scope.
29952999
if (R.empty()) {
2996-
if (NewScope == AFS_Class)
3000+
if (NewScope == AllocationFunctionScope::Class)
29973001
return true;
29983002

29993003
LookupQualifiedName(R, Context.getTranslationUnitDecl());
@@ -3043,7 +3047,8 @@ bool Sema::FindAllocationFunctions(
30433047
// the allocated type is not a class type or array thereof, the
30443048
// deallocation function's name is looked up in the global scope.
30453049
LookupResult FoundDelete(*this, DeleteName, StartLoc, LookupOrdinaryName);
3046-
if (AllocElemType->isRecordType() && DeleteScope != AFS_Global) {
3050+
if (AllocElemType->isRecordType() &&
3051+
DeleteScope != AllocationFunctionScope::Global) {
30473052
auto *RD =
30483053
cast<CXXRecordDecl>(AllocElemType->castAs<RecordType>()->getDecl());
30493054
LookupQualifiedName(FoundDelete, RD);
@@ -3086,7 +3091,7 @@ bool Sema::FindAllocationFunctions(
30863091
if (FoundDelete.empty()) {
30873092
FoundDelete.clear(LookupOrdinaryName);
30883093

3089-
if (DeleteScope == AFS_Class)
3094+
if (DeleteScope == AllocationFunctionScope::Class)
30903095
return true;
30913096

30923097
DeclareGlobalNewDelete();

0 commit comments

Comments
 (0)