@@ -10872,7 +10872,7 @@ bool Sema::CheckDestructor(CXXDestructorDecl *Destructor) {
1087210872 // first parameter, perform that conversion now.
1087310873 if (OperatorDelete->isDestroyingOperatorDelete()) {
1087410874 unsigned PointerParam = 0;
10875- if (isTypeAwareOperatorNewOrDelete(OperatorDelete ))
10875+ if (OperatorDelete-> isTypeAwareOperatorNewOrDelete())
1087610876 ++PointerParam;
1087710877 QualType ParamType =
1087810878 OperatorDelete->getParamDecl(PointerParam)->getType();
@@ -16127,72 +16127,53 @@ bool Sema::CompleteConstructorCall(CXXConstructorDecl *Constructor,
1612716127 return Invalid;
1612816128}
1612916129
16130- bool Sema::isTypeIdentitySpecialization(QualType Type) const {
16131- const ClassTemplateDecl *TypeIdentity = getStdTypeIdentity();
16132- if (!TypeIdentity)
16133- return false;
16134- const TemplateDecl *SpecializedDecl = Type->getSpecializedTemplateDecl();
16135- return TypeIdentity == SpecializedDecl;
16136- }
16137-
16138- bool Sema::isTypeAwareOperatorNewOrDelete(const FunctionDecl *FnDecl) const {
16139- // Type aware operators
16140- if (FnDecl->getNumParams() < 2)
16141- return false;
16142- const ParmVarDecl *ParamDecl = FnDecl->getParamDecl(0);
16143- return isTypeIdentitySpecialization(ParamDecl->getType());
16144- }
16145-
16146- bool Sema::isTypeAwareOperatorNewOrDelete(
16147- const FunctionTemplateDecl *FTD) const {
16148- return isTypeAwareOperatorNewOrDelete(FTD->getTemplatedDecl());
16149- }
16150-
1615116130bool Sema::isTypeAwareOperatorNewOrDelete(const NamedDecl *ND) const {
16131+ const FunctionDecl *FnDecl = nullptr;
1615216132 if (auto *FTD = dyn_cast<FunctionTemplateDecl>(ND))
16153- return isTypeAwareOperatorNewOrDelete(FTD->getTemplatedDecl());
16154- if (auto *FnDecl = dyn_cast<FunctionDecl>(ND))
16155- return isTypeAwareOperatorNewOrDelete(FnDecl);
16156- return false;
16133+ FnDecl = FTD->getTemplatedDecl();
16134+ else if (auto *FD = dyn_cast<FunctionDecl>(ND))
16135+ FnDecl = FD;
16136+
16137+ return FnDecl->isTypeAwareOperatorNewOrDelete();
1615716138}
1615816139
16159- std::optional< FunctionDecl *>
16140+ FunctionDecl *
1616016141Sema::instantiateTypeAwareUsualDelete(FunctionTemplateDecl *FnTemplateDecl,
1616116142 QualType DeallocType) {
1616216143 if (!isTypeAwareAllocation(allocationModeInCurrentContext()))
16163- return std::nullopt ;
16144+ return nullptr ;
1616416145
1616516146 TemplateParameterList *TemplateParameters =
1616616147 FnTemplateDecl->getTemplateParameters();
1616716148 if (TemplateParameters->hasParameterPack())
16168- return std::nullopt ;
16149+ return nullptr ;
1616916150
1617016151 FunctionDecl *FnDecl = FnTemplateDecl->getTemplatedDecl();
16171- if (!isTypeAwareOperatorNewOrDelete(FnDecl ))
16172- return std::nullopt ;
16152+ if (!FnDecl-> isTypeAwareOperatorNewOrDelete())
16153+ return nullptr ;
1617316154
1617416155 if (FnDecl->isVariadic())
16175- return std::nullopt ;
16156+ return nullptr ;
1617616157
1617716158 unsigned NumParams = FnDecl->getNumParams();
1617816159 if (NumParams < 2)
16179- return std::nullopt ;
16160+ return nullptr ;
1618016161
1618116162 for (size_t Idx = 1; Idx < NumParams; ++Idx) {
1618216163 // A type aware allocation is only usual if the only dependent parameter is
1618316164 // the first parameter.
1618416165 const ParmVarDecl *ParamDecl = FnDecl->getParamDecl(Idx);
1618516166 if (ParamDecl->getType()->isDependentType())
16186- return std::nullopt ;
16167+ return nullptr ;
1618716168 }
1618816169
16189- std::optional< QualType> SpecializedTypeIdentity =
16170+ QualType SpecializedTypeIdentity =
1619016171 instantiateSpecializedTypeIdentity(DeallocType);
16191- if (! SpecializedTypeIdentity)
16192- return std::nullopt ;
16172+ if (SpecializedTypeIdentity.isNull() )
16173+ return nullptr ;
1619316174 SmallVector<QualType, 4> ArgTypes;
1619416175 ArgTypes.reserve(NumParams);
16195- ArgTypes.push_back(* SpecializedTypeIdentity);
16176+ ArgTypes.push_back(SpecializedTypeIdentity);
1619616177 ArgTypes.push_back(FnDecl->getParamDecl(1)->getType());
1619716178 unsigned UsualParamsIdx = 2;
1619816179 if (UsualParamsIdx < NumParams && FnDecl->isDestroyingOperatorDelete()) {
@@ -16218,7 +16199,7 @@ Sema::instantiateTypeAwareUsualDelete(FunctionTemplateDecl *FnTemplateDecl,
1621816199 }
1621916200
1622016201 if (UsualParamsIdx != NumParams)
16221- return std::nullopt ;
16202+ return nullptr ;
1622216203
1622316204 FunctionProtoType::ExtProtoInfo EPI;
1622416205 QualType ExpectedFunctionType =
@@ -16228,24 +16209,23 @@ Sema::instantiateTypeAwareUsualDelete(FunctionTemplateDecl *FnTemplateDecl,
1622816209 FunctionDecl *Result;
1622916210 if (DeduceTemplateArguments(FnTemplateDecl, nullptr, ExpectedFunctionType,
1623016211 Result, Info) != TemplateDeductionResult::Success)
16231- return std::nullopt ;
16212+ return nullptr ;
1623216213 return Result;
1623316214}
1623416215
16235- std::optional<QualType>
16236- Sema::instantiateSpecializedTypeIdentity(QualType Subject) {
16216+ QualType Sema::instantiateSpecializedTypeIdentity(QualType Subject) {
1623716217 assert(clang::isTypeAwareAllocation(allocationModeInCurrentContext()));
1623816218 ClassTemplateDecl *TypeIdentity = getStdTypeIdentity();
1623916219 if (!TypeIdentity)
16240- return std::nullopt ;
16220+ return QualType() ;
1624116221
1624216222 auto TN = TemplateName(TypeIdentity);
1624316223 TemplateArgumentListInfo Arguments;
1624416224 Arguments.addArgument(getTrivialTemplateArgumentLoc(
1624516225 TemplateArgument(Subject), QualType(), SourceLocation()));
1624616226 QualType Result = CheckTemplateIdType(TN, SourceLocation(), Arguments);
1624716227 if (Result.isNull())
16248- return std::nullopt ;
16228+ return QualType() ;
1624916229 return Result;
1625016230}
1625116231
0 commit comments