Skip to content

Commit 7cbb141

Browse files
[clang] Migrate away from ArrayRef(std::nullopt) (NFC) (#144982)
ArrayRef has a constructor that accepts std::nullopt. This constructor dates back to the days when we still had llvm::Optional. Since the use of std::nullopt outside the context of std::optional is kind of abuse and not intuitive to new comers, I would like to move away from the constructor and eventually remove it. This patch takes care of the clang side of the migration.
1 parent b8d3efa commit 7cbb141

File tree

12 files changed

+17
-18
lines changed

12 files changed

+17
-18
lines changed

clang/include/clang/AST/TypeProperties.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ let Class = TemplateSpecializationType in {
753753
}
754754

755755
def : Creator<[{
756-
return ctx.getTemplateSpecializationType(templateName, args, std::nullopt, UnderlyingType);
756+
return ctx.getTemplateSpecializationType(templateName, args, {}, UnderlyingType);
757757
}]>;
758758
}
759759

clang/lib/AST/ASTContext.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14283,7 +14283,7 @@ static QualType getCommonNonSugarTypeNode(ASTContext &Ctx, const Type *X,
1428314283
::getCommonTemplateNameChecked(Ctx, TX->getTemplateName(),
1428414284
TY->getTemplateName(),
1428514285
/*IgnoreDeduced=*/true),
14286-
As, /*CanonicalArgs=*/std::nullopt, X->getCanonicalTypeInternal());
14286+
As, /*CanonicalArgs=*/{}, X->getCanonicalTypeInternal());
1428714287
}
1428814288
case Type::Decltype: {
1428914289
const auto *DX = cast<DecltypeType>(X);
@@ -14529,7 +14529,7 @@ static QualType getCommonSugarTypeNode(ASTContext &Ctx, const Type *X,
1452914529
TY->template_arguments()))
1453014530
return QualType();
1453114531
return Ctx.getTemplateSpecializationType(CTN, As,
14532-
/*CanonicalArgs=*/std::nullopt,
14532+
/*CanonicalArgs=*/{},
1453314533
Ctx.getQualifiedType(Underlying));
1453414534
}
1453514535
case Type::Typedef: {

clang/lib/AST/ASTDiagnostic.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ QualType clang::desugarForDiagnostic(ASTContext &Context, QualType QT,
130130
if (DesugarArgument) {
131131
ShouldAKA = true;
132132
QT = Context.getTemplateSpecializationType(
133-
TST->getTemplateName(), Args, /*CanonicalArgs=*/std::nullopt, QT);
133+
TST->getTemplateName(), Args, /*CanonicalArgs=*/{}, QT);
134134
}
135135
break;
136136
}
@@ -1143,7 +1143,7 @@ class TemplateDiff {
11431143

11441144
Ty = Context.getTemplateSpecializationType(
11451145
TemplateName(CTSD->getSpecializedTemplate()),
1146-
CTSD->getTemplateArgs().asArray(), /*CanonicalArgs=*/std::nullopt,
1146+
CTSD->getTemplateArgs().asArray(), /*CanonicalArgs=*/{},
11471147
Ty.getLocalUnqualifiedType().getCanonicalType());
11481148

11491149
return Ty->getAs<TemplateSpecializationType>();

clang/lib/AST/ASTImporter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1664,7 +1664,7 @@ ExpectedType ASTNodeImporter::VisitTemplateSpecializationType(
16641664
if (!ToUnderlyingOrErr)
16651665
return ToUnderlyingOrErr.takeError();
16661666
return Importer.getToContext().getTemplateSpecializationType(
1667-
*ToTemplateOrErr, ToTemplateArgs, std::nullopt, *ToUnderlyingOrErr);
1667+
*ToTemplateOrErr, ToTemplateArgs, {}, *ToUnderlyingOrErr);
16681668
}
16691669

16701670
ExpectedType ASTNodeImporter::VisitElaboratedType(const ElaboratedType *T) {

clang/lib/AST/DeclTemplate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ ClassTemplateDecl::getInjectedClassNameSpecialization() {
669669
CommonPtr->InjectedClassNameType =
670670
Context.getTemplateSpecializationType(Name,
671671
/*SpecifiedArgs=*/TemplateArgs,
672-
/*CanonicalArgs=*/std::nullopt);
672+
/*CanonicalArgs=*/{});
673673
return CommonPtr->InjectedClassNameType;
674674
}
675675

clang/lib/AST/QualTypeNames.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ static const Type *getFullyQualifiedTemplateType(const ASTContext &Ctx,
140140
if (MightHaveChanged) {
141141
QualType QT = Ctx.getTemplateSpecializationType(
142142
TST->getTemplateName(), FQArgs,
143-
/*CanonicalArgs=*/std::nullopt, TST->desugar());
143+
/*CanonicalArgs=*/{}, TST->desugar());
144144
// getTemplateSpecializationType returns a fully qualified
145145
// version of the specialization itself, so no need to qualify
146146
// it.
@@ -172,8 +172,7 @@ static const Type *getFullyQualifiedTemplateType(const ASTContext &Ctx,
172172
TemplateName TN(TSTDecl->getSpecializedTemplate());
173173
QualType QT = Ctx.getTemplateSpecializationType(
174174
TN, FQArgs,
175-
/*CanonicalArgs=*/std::nullopt,
176-
TSTRecord->getCanonicalTypeInternal());
175+
/*CanonicalArgs=*/{}, TSTRecord->getCanonicalTypeInternal());
177176
// getTemplateSpecializationType returns a fully qualified
178177
// version of the specialization itself, so no need to qualify
179178
// it.

clang/lib/Basic/Targets/Xtensa.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class LLVM_LIBRARY_VISIBILITY XtensaTargetInfo : public TargetInfo {
7777
}
7878

7979
ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override {
80-
return std::nullopt;
80+
return {};
8181
}
8282

8383
bool validateAsmConstraint(const char *&Name,

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2032,7 +2032,7 @@ Value *CodeGenFunction::EmitCheckedArgForAssume(const Expr *E) {
20322032
std::make_pair(ArgValue, CheckOrdinal), CheckHandler,
20332033
{EmitCheckSourceLocation(E->getExprLoc()),
20342034
llvm::ConstantInt::get(Builder.getInt8Ty(), BCK_AssumePassedFalse)},
2035-
std::nullopt);
2035+
{});
20362036
return ArgValue;
20372037
}
20382038

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8953,7 +8953,7 @@ void OffloadBundler::ConstructJob(Compilation &C, const JobAction &JA,
89538953
C.addCommand(std::make_unique<Command>(
89548954
JA, *this, ResponseFileSupport::None(),
89558955
TCArgs.MakeArgString(getToolChain().GetProgramPath(getShortName())),
8956-
CmdArgs, std::nullopt, Output));
8956+
CmdArgs, ArrayRef<InputInfo>(), Output));
89578957
}
89588958

89598959
void OffloadBundler::ConstructJobMultipleOutputs(
@@ -9040,7 +9040,7 @@ void OffloadBundler::ConstructJobMultipleOutputs(
90409040
C.addCommand(std::make_unique<Command>(
90419041
JA, *this, ResponseFileSupport::None(),
90429042
TCArgs.MakeArgString(getToolChain().GetProgramPath(getShortName())),
9043-
CmdArgs, std::nullopt, Outputs));
9043+
CmdArgs, ArrayRef<InputInfo>(), Outputs));
90449044
}
90459045

90469046
void OffloadPackager::ConstructJob(Compilation &C, const JobAction &JA,

clang/lib/Sema/SemaConcept.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,10 +1081,10 @@ static bool CheckFunctionConstraintsWithoutInstantiation(
10811081
// FIXME: Add TemplateArgs through the 'Innermost' parameter once
10821082
// the refactoring of getTemplateInstantiationArgs() relands.
10831083
MultiLevelTemplateArgumentList MLTAL;
1084-
MLTAL.addOuterTemplateArguments(Template, std::nullopt, /*Final=*/false);
1084+
MLTAL.addOuterTemplateArguments(Template, {}, /*Final=*/false);
10851085
SemaRef.getTemplateInstantiationArgs(
10861086
MLTAL, /*D=*/FD, FD,
1087-
/*Final=*/false, /*Innermost=*/std::nullopt, /*RelativeToPrimary=*/true,
1087+
/*Final=*/false, /*Innermost=*/{}, /*RelativeToPrimary=*/true,
10881088
/*Pattern=*/nullptr, /*ForConstraintInstantiation=*/true);
10891089
MLTAL.replaceInnermostTemplateArguments(Template, TemplateArgs);
10901090

clang/lib/Sema/SemaExpr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21212,7 +21212,7 @@ ExprResult Sema::CheckPlaceholderExpr(Expr *E) {
2121221212
}
2121321213
if (TST.isNull())
2121421214
TST = Context.getTemplateSpecializationType(
21215-
TN, ULE->template_arguments(), /*CanonicalArgs=*/std::nullopt,
21215+
TN, ULE->template_arguments(), /*CanonicalArgs=*/{},
2121621216
HasAnyDependentTA ? Context.DependentTy : Context.IntTy);
2121721217
QualType ET =
2121821218
Context.getElaboratedType(ElaboratedTypeKeyword::None, NNS, TST);

clang/lib/Sema/TreeTransform.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16222,7 +16222,7 @@ TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
1622216222
return getDerived().RebuildSizeOfPackExpr(
1622316223
E->getOperatorLoc(), E->getPack(), E->getPackLoc(), E->getRParenLoc(),
1622416224
/*Length=*/static_cast<unsigned>(Args.size()),
16225-
/*PartialArgs=*/std::nullopt);
16225+
/*PartialArgs=*/{});
1622616226
}
1622716227

1622816228
template <typename Derived>

0 commit comments

Comments
 (0)