Skip to content

Commit 4dd55c5

Browse files
authored
[clang] Use {} instead of std::nullopt to initialize empty ArrayRef (#109399)
Follow up to #109133.
1 parent e37d736 commit 4dd55c5

File tree

115 files changed

+376
-435
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+376
-435
lines changed

clang/include/clang/AST/CommentSema.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class Sema {
8080
ArrayRef<T> copyArray(ArrayRef<T> Source) {
8181
if (!Source.empty())
8282
return Source.copy(Allocator);
83-
return std::nullopt;
83+
return {};
8484
}
8585

8686
ParagraphComment *actOnParagraphComment(

clang/include/clang/AST/DeclFriend.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class FriendDecl final
115115
static FriendDecl *
116116
Create(ASTContext &C, DeclContext *DC, SourceLocation L, FriendUnion Friend_,
117117
SourceLocation FriendL, SourceLocation EllipsisLoc = {},
118-
ArrayRef<TemplateParameterList *> FriendTypeTPLists = std::nullopt);
118+
ArrayRef<TemplateParameterList *> FriendTypeTPLists = {});
119119
static FriendDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID,
120120
unsigned FriendTypeNumTPLists);
121121

clang/include/clang/AST/DeclObjC.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ class ObjCMethodDecl : public NamedDecl, public DeclContext {
386386
/// If the method is implicit (not coming from source) \p SelLocs is
387387
/// ignored.
388388
void setMethodParams(ASTContext &C, ArrayRef<ParmVarDecl *> Params,
389-
ArrayRef<SourceLocation> SelLocs = std::nullopt);
389+
ArrayRef<SourceLocation> SelLocs = {});
390390

391391
// Iterator access to parameter types.
392392
struct GetTypeFn {

clang/include/clang/AST/DeclOpenMP.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ template <typename U> class OMPDeclarativeDirective : public U {
3434
/// Get the clauses storage.
3535
MutableArrayRef<OMPClause *> getClauses() {
3636
if (!Data)
37-
return std::nullopt;
37+
return {};
3838
return Data->getClauses();
3939
}
4040

@@ -90,7 +90,7 @@ template <typename U> class OMPDeclarativeDirective : public U {
9090

9191
ArrayRef<OMPClause *> clauses() const {
9292
if (!Data)
93-
return std::nullopt;
93+
return {};
9494
return Data->getClauses();
9595
}
9696
};

clang/include/clang/AST/ExprCXX.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -4306,11 +4306,11 @@ class SizeOfPackExpr final
43064306
: Expr(SizeOfPackExprClass, Empty), Length(NumPartialArgs) {}
43074307

43084308
public:
4309-
static SizeOfPackExpr *
4310-
Create(ASTContext &Context, SourceLocation OperatorLoc, NamedDecl *Pack,
4311-
SourceLocation PackLoc, SourceLocation RParenLoc,
4312-
std::optional<unsigned> Length = std::nullopt,
4313-
ArrayRef<TemplateArgument> PartialArgs = std::nullopt);
4309+
static SizeOfPackExpr *Create(ASTContext &Context, SourceLocation OperatorLoc,
4310+
NamedDecl *Pack, SourceLocation PackLoc,
4311+
SourceLocation RParenLoc,
4312+
std::optional<unsigned> Length = std::nullopt,
4313+
ArrayRef<TemplateArgument> PartialArgs = {});
43144314
static SizeOfPackExpr *CreateDeserialized(ASTContext &Context,
43154315
unsigned NumPartialArgs);
43164316

clang/include/clang/AST/OpenMPClause.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -6108,14 +6108,14 @@ class OMPMappableExprListClause : public OMPVarListClause<T>,
61086108
return const_component_lists_iterator(
61096109
getUniqueDeclsRef(), getDeclNumListsRef(), getComponentListSizesRef(),
61106110
getComponentsRef(), SupportsMapper,
6111-
SupportsMapper ? getUDMapperRefs() : std::nullopt);
6111+
SupportsMapper ? getUDMapperRefs() : ArrayRef<Expr *>());
61126112
}
61136113
const_component_lists_iterator component_lists_end() const {
61146114
return const_component_lists_iterator(
61156115
ArrayRef<ValueDecl *>(), ArrayRef<unsigned>(), ArrayRef<unsigned>(),
61166116
MappableExprComponentListRef(getComponentsRef().end(),
61176117
getComponentsRef().end()),
6118-
SupportsMapper, std::nullopt);
6118+
SupportsMapper, {});
61196119
}
61206120
const_component_lists_range component_lists() const {
61216121
return {component_lists_begin(), component_lists_end()};
@@ -6128,7 +6128,7 @@ class OMPMappableExprListClause : public OMPVarListClause<T>,
61286128
return const_component_lists_iterator(
61296129
VD, getUniqueDeclsRef(), getDeclNumListsRef(),
61306130
getComponentListSizesRef(), getComponentsRef(), SupportsMapper,
6131-
SupportsMapper ? getUDMapperRefs() : std::nullopt);
6131+
SupportsMapper ? getUDMapperRefs() : ArrayRef<Expr *>());
61326132
}
61336133
const_component_lists_iterator decl_component_lists_end() const {
61346134
return component_lists_end();

clang/include/clang/AST/StmtOpenMP.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ class OMPExecutableDirective : public Stmt {
277277
/// Get the clauses storage.
278278
MutableArrayRef<OMPClause *> getClauses() {
279279
if (!Data)
280-
return std::nullopt;
280+
return {};
281281
return Data->getClauses();
282282
}
283283

@@ -572,7 +572,7 @@ class OMPExecutableDirective : public Stmt {
572572

573573
ArrayRef<OMPClause *> clauses() const {
574574
if (!Data)
575-
return std::nullopt;
575+
return {};
576576
return Data->getClauses();
577577
}
578578

clang/include/clang/AST/TemplateBase.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ class TemplateArgument {
283283
}
284284

285285
static TemplateArgument getEmptyPack() {
286-
return TemplateArgument(std::nullopt);
286+
return TemplateArgument(ArrayRef<TemplateArgument>());
287287
}
288288

289289
/// Create a new template argument pack by copying the given set of

clang/include/clang/ASTMatchers/ASTMatchersInternal.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ template <typename T> struct TypeListContainsSuperOf<EmptyTypeList, T> {
121121
template <typename ResultT, typename ArgT,
122122
ResultT (*Func)(ArrayRef<const ArgT *>)>
123123
struct VariadicFunction {
124-
ResultT operator()() const { return Func(std::nullopt); }
124+
ResultT operator()() const { return Func({}); }
125125

126126
template <typename... ArgsT>
127127
ResultT operator()(const ArgT &Arg1, const ArgsT &... Args) const {
@@ -1949,35 +1949,35 @@ inline ArrayRef<TemplateArgument>
19491949
getTemplateSpecializationArgs(const FunctionDecl &FD) {
19501950
if (const auto* TemplateArgs = FD.getTemplateSpecializationArgs())
19511951
return TemplateArgs->asArray();
1952-
return std::nullopt;
1952+
return {};
19531953
}
19541954

19551955
inline ArrayRef<TemplateArgumentLoc>
19561956
getTemplateArgsWritten(const ClassTemplateSpecializationDecl &D) {
19571957
if (const ASTTemplateArgumentListInfo *Args = D.getTemplateArgsAsWritten())
19581958
return Args->arguments();
1959-
return std::nullopt;
1959+
return {};
19601960
}
19611961

19621962
inline ArrayRef<TemplateArgumentLoc>
19631963
getTemplateArgsWritten(const VarTemplateSpecializationDecl &D) {
19641964
if (const ASTTemplateArgumentListInfo *Args = D.getTemplateArgsAsWritten())
19651965
return Args->arguments();
1966-
return std::nullopt;
1966+
return {};
19671967
}
19681968

19691969
inline ArrayRef<TemplateArgumentLoc>
19701970
getTemplateArgsWritten(const FunctionDecl &FD) {
19711971
if (const auto *Args = FD.getTemplateSpecializationArgsAsWritten())
19721972
return Args->arguments();
1973-
return std::nullopt;
1973+
return {};
19741974
}
19751975

19761976
inline ArrayRef<TemplateArgumentLoc>
19771977
getTemplateArgsWritten(const DeclRefExpr &DRE) {
19781978
if (const auto *Args = DRE.getTemplateArgs())
19791979
return {Args, DRE.getNumTemplateArgs()};
1980-
return std::nullopt;
1980+
return {};
19811981
}
19821982

19831983
inline SmallVector<TemplateArgumentLoc>

clang/include/clang/Analysis/Analyses/ThreadSafetyTIL.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1470,7 +1470,7 @@ class Return : public Terminator {
14701470
static bool classof(const SExpr *E) { return E->opcode() == COP_Return; }
14711471

14721472
/// Return an empty list.
1473-
ArrayRef<BasicBlock *> successors() { return std::nullopt; }
1473+
ArrayRef<BasicBlock *> successors() { return {}; }
14741474

14751475
SExpr *returnValue() { return Retval; }
14761476
const SExpr *returnValue() const { return Retval; }
@@ -1496,7 +1496,7 @@ inline ArrayRef<BasicBlock*> Terminator::successors() {
14961496
case COP_Branch: return cast<Branch>(this)->successors();
14971497
case COP_Return: return cast<Return>(this)->successors();
14981498
default:
1499-
return std::nullopt;
1499+
return {};
15001500
}
15011501
}
15021502

clang/include/clang/Analysis/AnyCall.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ class AnyCall {
143143
/// \returns formal parameters for direct calls (including virtual calls)
144144
ArrayRef<ParmVarDecl *> parameters() const {
145145
if (!D)
146-
return std::nullopt;
146+
return {};
147147

148148
if (const auto *FD = dyn_cast<FunctionDecl>(D)) {
149149
return FD->parameters();
@@ -152,7 +152,7 @@ class AnyCall {
152152
} else if (const auto *BD = dyn_cast<BlockDecl>(D)) {
153153
return BD->parameters();
154154
} else {
155-
return std::nullopt;
155+
return {};
156156
}
157157
}
158158

clang/include/clang/Basic/TargetInfo.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -1858,11 +1858,9 @@ class TargetInfo : public TransferrableTargetInfo,
18581858
}
18591859
virtual ArrayRef<const char *> getGCCRegNames() const = 0;
18601860
virtual ArrayRef<GCCRegAlias> getGCCRegAliases() const = 0;
1861-
virtual ArrayRef<AddlRegName> getGCCAddlRegNames() const {
1862-
return std::nullopt;
1863-
}
1861+
virtual ArrayRef<AddlRegName> getGCCAddlRegNames() const { return {}; }
18641862

1865-
private:
1863+
private:
18661864
// Assert the values for the fractional and integral bits for each fixed point
18671865
// type follow the restrictions given in clause 6.2.6.3 of N1169.
18681866
void CheckFixedPointBits() const;

clang/include/clang/Driver/Job.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,7 @@ class Command {
172172
Command(const Action &Source, const Tool &Creator,
173173
ResponseFileSupport ResponseSupport, const char *Executable,
174174
const llvm::opt::ArgStringList &Arguments, ArrayRef<InputInfo> Inputs,
175-
ArrayRef<InputInfo> Outputs = std::nullopt,
176-
const char *PrependArg = nullptr);
175+
ArrayRef<InputInfo> Outputs = {}, const char *PrependArg = nullptr);
177176
// FIXME: This really shouldn't be copyable, but is currently copied in some
178177
// error handling in Driver::generateCompilationDiagnostics.
179178
Command(const Command &) = default;
@@ -245,8 +244,7 @@ class CC1Command : public Command {
245244
CC1Command(const Action &Source, const Tool &Creator,
246245
ResponseFileSupport ResponseSupport, const char *Executable,
247246
const llvm::opt::ArgStringList &Arguments,
248-
ArrayRef<InputInfo> Inputs,
249-
ArrayRef<InputInfo> Outputs = std::nullopt,
247+
ArrayRef<InputInfo> Inputs, ArrayRef<InputInfo> Outputs = {},
250248
const char *PrependArg = nullptr);
251249

252250
void Print(llvm::raw_ostream &OS, const char *Terminator, bool Quote,

clang/include/clang/Frontend/ASTUnit.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ class ASTUnit {
836836
bool StorePreamblesInMemory = false,
837837
StringRef PreambleStoragePath = StringRef(), bool OnlyLocalDecls = false,
838838
CaptureDiagsKind CaptureDiagnostics = CaptureDiagsKind::None,
839-
ArrayRef<RemappedFile> RemappedFiles = std::nullopt,
839+
ArrayRef<RemappedFile> RemappedFiles = {},
840840
bool RemappedFilesKeepOriginalName = true,
841841
unsigned PrecompilePreambleAfterNParses = 0,
842842
TranslationUnitKind TUKind = TU_Complete,
@@ -864,7 +864,7 @@ class ASTUnit {
864864
/// \returns True if a failure occurred that causes the ASTUnit not to
865865
/// contain any translation-unit information, false otherwise.
866866
bool Reparse(std::shared_ptr<PCHContainerOperations> PCHContainerOps,
867-
ArrayRef<RemappedFile> RemappedFiles = std::nullopt,
867+
ArrayRef<RemappedFile> RemappedFiles = {},
868868
IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS = nullptr);
869869

870870
/// Free data that will be re-generated on the next parse.

clang/include/clang/Lex/Preprocessor.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,7 @@ class Preprocessor {
911911
getActiveModuleMacros(Preprocessor &PP, const IdentifierInfo *II) const {
912912
if (auto *Info = getModuleInfo(PP, II))
913913
return Info->ActiveModuleMacros;
914-
return std::nullopt;
914+
return {};
915915
}
916916

917917
MacroDirective::DefInfo findDirectiveAtLoc(SourceLocation Loc,
@@ -935,7 +935,7 @@ class Preprocessor {
935935
ArrayRef<ModuleMacro*> getOverriddenMacros() const {
936936
if (auto *Info = State.dyn_cast<ModuleMacroInfo*>())
937937
return Info->OverriddenMacros;
938-
return std::nullopt;
938+
return {};
939939
}
940940

941941
void setOverriddenMacros(Preprocessor &PP,
@@ -1444,7 +1444,7 @@ class Preprocessor {
14441444
auto I = LeafModuleMacros.find(II);
14451445
if (I != LeafModuleMacros.end())
14461446
return I->second;
1447-
return std::nullopt;
1447+
return {};
14481448
}
14491449

14501450
/// Get the list of submodules that we're currently building.

clang/include/clang/Sema/CodeCompleteConsumer.h

+3-4
Original file line numberDiff line numberDiff line change
@@ -375,12 +375,11 @@ class CodeCompletionContext {
375375
public:
376376
/// Construct a new code-completion context of the given kind.
377377
CodeCompletionContext(Kind CCKind)
378-
: CCKind(CCKind), IsUsingDeclaration(false), SelIdents(std::nullopt) {}
378+
: CCKind(CCKind), IsUsingDeclaration(false), SelIdents() {}
379379

380380
/// Construct a new code-completion context of the given kind.
381-
CodeCompletionContext(
382-
Kind CCKind, QualType T,
383-
ArrayRef<const IdentifierInfo *> SelIdents = std::nullopt)
381+
CodeCompletionContext(Kind CCKind, QualType T,
382+
ArrayRef<const IdentifierInfo *> SelIdents = {})
384383
: CCKind(CCKind), IsUsingDeclaration(false), SelIdents(SelIdents) {
385384
if (CCKind == CCC_DotMemberAccess || CCKind == CCC_ArrowMemberAccess ||
386385
CCKind == CCC_ObjCPropertyAccess || CCKind == CCC_ObjCClassMessage ||

clang/include/clang/Sema/Overload.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -1206,9 +1206,8 @@ class Sema;
12061206

12071207
/// Add a new candidate with NumConversions conversion sequence slots
12081208
/// to the overload set.
1209-
OverloadCandidate &
1210-
addCandidate(unsigned NumConversions = 0,
1211-
ConversionSequenceList Conversions = std::nullopt) {
1209+
OverloadCandidate &addCandidate(unsigned NumConversions = 0,
1210+
ConversionSequenceList Conversions = {}) {
12121211
assert((Conversions.empty() || Conversions.size() == NumConversions) &&
12131212
"preallocated conversion sequence has wrong length");
12141213

0 commit comments

Comments
 (0)