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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 5 additions & 5 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 6 additions & 6 deletions
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

Lines changed: 2 additions & 2 deletions
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

0 commit comments

Comments
 (0)