Skip to content

[clang] Use {} instead of std::nullopt to initialize empty ArrayRef #109399

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clang/include/clang/AST/CommentSema.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class Sema {
ArrayRef<T> copyArray(ArrayRef<T> Source) {
if (!Source.empty())
return Source.copy(Allocator);
return std::nullopt;
return {};
}

ParagraphComment *actOnParagraphComment(
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/AST/DeclFriend.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class FriendDecl final
static FriendDecl *
Create(ASTContext &C, DeclContext *DC, SourceLocation L, FriendUnion Friend_,
SourceLocation FriendL, SourceLocation EllipsisLoc = {},
ArrayRef<TemplateParameterList *> FriendTypeTPLists = std::nullopt);
ArrayRef<TemplateParameterList *> FriendTypeTPLists = {});
static FriendDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID,
unsigned FriendTypeNumTPLists);

Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/AST/DeclObjC.h
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ class ObjCMethodDecl : public NamedDecl, public DeclContext {
/// If the method is implicit (not coming from source) \p SelLocs is
/// ignored.
void setMethodParams(ASTContext &C, ArrayRef<ParmVarDecl *> Params,
ArrayRef<SourceLocation> SelLocs = std::nullopt);
ArrayRef<SourceLocation> SelLocs = {});

// Iterator access to parameter types.
struct GetTypeFn {
Expand Down
4 changes: 2 additions & 2 deletions clang/include/clang/AST/DeclOpenMP.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ template <typename U> class OMPDeclarativeDirective : public U {
/// Get the clauses storage.
MutableArrayRef<OMPClause *> getClauses() {
if (!Data)
return std::nullopt;
return {};
return Data->getClauses();
}

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

ArrayRef<OMPClause *> clauses() const {
if (!Data)
return std::nullopt;
return {};
return Data->getClauses();
}
};
Expand Down
10 changes: 5 additions & 5 deletions clang/include/clang/AST/ExprCXX.h
Original file line number Diff line number Diff line change
Expand Up @@ -4306,11 +4306,11 @@ class SizeOfPackExpr final
: Expr(SizeOfPackExprClass, Empty), Length(NumPartialArgs) {}

public:
static SizeOfPackExpr *
Create(ASTContext &Context, SourceLocation OperatorLoc, NamedDecl *Pack,
SourceLocation PackLoc, SourceLocation RParenLoc,
std::optional<unsigned> Length = std::nullopt,
ArrayRef<TemplateArgument> PartialArgs = std::nullopt);
static SizeOfPackExpr *Create(ASTContext &Context, SourceLocation OperatorLoc,
NamedDecl *Pack, SourceLocation PackLoc,
SourceLocation RParenLoc,
std::optional<unsigned> Length = std::nullopt,
ArrayRef<TemplateArgument> PartialArgs = {});
static SizeOfPackExpr *CreateDeserialized(ASTContext &Context,
unsigned NumPartialArgs);

Expand Down
6 changes: 3 additions & 3 deletions clang/include/clang/AST/OpenMPClause.h
Original file line number Diff line number Diff line change
Expand Up @@ -6108,14 +6108,14 @@ class OMPMappableExprListClause : public OMPVarListClause<T>,
return const_component_lists_iterator(
getUniqueDeclsRef(), getDeclNumListsRef(), getComponentListSizesRef(),
getComponentsRef(), SupportsMapper,
SupportsMapper ? getUDMapperRefs() : std::nullopt);
SupportsMapper ? getUDMapperRefs() : ArrayRef<Expr *>());
}
const_component_lists_iterator component_lists_end() const {
return const_component_lists_iterator(
ArrayRef<ValueDecl *>(), ArrayRef<unsigned>(), ArrayRef<unsigned>(),
MappableExprComponentListRef(getComponentsRef().end(),
getComponentsRef().end()),
SupportsMapper, std::nullopt);
SupportsMapper, {});
}
const_component_lists_range component_lists() const {
return {component_lists_begin(), component_lists_end()};
Expand All @@ -6128,7 +6128,7 @@ class OMPMappableExprListClause : public OMPVarListClause<T>,
return const_component_lists_iterator(
VD, getUniqueDeclsRef(), getDeclNumListsRef(),
getComponentListSizesRef(), getComponentsRef(), SupportsMapper,
SupportsMapper ? getUDMapperRefs() : std::nullopt);
SupportsMapper ? getUDMapperRefs() : ArrayRef<Expr *>());
}
const_component_lists_iterator decl_component_lists_end() const {
return component_lists_end();
Expand Down
4 changes: 2 additions & 2 deletions clang/include/clang/AST/StmtOpenMP.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ class OMPExecutableDirective : public Stmt {
/// Get the clauses storage.
MutableArrayRef<OMPClause *> getClauses() {
if (!Data)
return std::nullopt;
return {};
return Data->getClauses();
}

Expand Down Expand Up @@ -572,7 +572,7 @@ class OMPExecutableDirective : public Stmt {

ArrayRef<OMPClause *> clauses() const {
if (!Data)
return std::nullopt;
return {};
return Data->getClauses();
}

Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/AST/TemplateBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ class TemplateArgument {
}

static TemplateArgument getEmptyPack() {
return TemplateArgument(std::nullopt);
return TemplateArgument(ArrayRef<TemplateArgument>());
}

/// Create a new template argument pack by copying the given set of
Expand Down
12 changes: 6 additions & 6 deletions clang/include/clang/ASTMatchers/ASTMatchersInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ template <typename T> struct TypeListContainsSuperOf<EmptyTypeList, T> {
template <typename ResultT, typename ArgT,
ResultT (*Func)(ArrayRef<const ArgT *>)>
struct VariadicFunction {
ResultT operator()() const { return Func(std::nullopt); }
ResultT operator()() const { return Func({}); }

template <typename... ArgsT>
ResultT operator()(const ArgT &Arg1, const ArgsT &... Args) const {
Expand Down Expand Up @@ -1949,35 +1949,35 @@ inline ArrayRef<TemplateArgument>
getTemplateSpecializationArgs(const FunctionDecl &FD) {
if (const auto* TemplateArgs = FD.getTemplateSpecializationArgs())
return TemplateArgs->asArray();
return std::nullopt;
return {};
}

inline ArrayRef<TemplateArgumentLoc>
getTemplateArgsWritten(const ClassTemplateSpecializationDecl &D) {
if (const ASTTemplateArgumentListInfo *Args = D.getTemplateArgsAsWritten())
return Args->arguments();
return std::nullopt;
return {};
}

inline ArrayRef<TemplateArgumentLoc>
getTemplateArgsWritten(const VarTemplateSpecializationDecl &D) {
if (const ASTTemplateArgumentListInfo *Args = D.getTemplateArgsAsWritten())
return Args->arguments();
return std::nullopt;
return {};
}

inline ArrayRef<TemplateArgumentLoc>
getTemplateArgsWritten(const FunctionDecl &FD) {
if (const auto *Args = FD.getTemplateSpecializationArgsAsWritten())
return Args->arguments();
return std::nullopt;
return {};
}

inline ArrayRef<TemplateArgumentLoc>
getTemplateArgsWritten(const DeclRefExpr &DRE) {
if (const auto *Args = DRE.getTemplateArgs())
return {Args, DRE.getNumTemplateArgs()};
return std::nullopt;
return {};
}

inline SmallVector<TemplateArgumentLoc>
Expand Down
4 changes: 2 additions & 2 deletions clang/include/clang/Analysis/Analyses/ThreadSafetyTIL.h
Original file line number Diff line number Diff line change
Expand Up @@ -1470,7 +1470,7 @@ class Return : public Terminator {
static bool classof(const SExpr *E) { return E->opcode() == COP_Return; }

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

SExpr *returnValue() { return Retval; }
const SExpr *returnValue() const { return Retval; }
Expand All @@ -1496,7 +1496,7 @@ inline ArrayRef<BasicBlock*> Terminator::successors() {
case COP_Branch: return cast<Branch>(this)->successors();
case COP_Return: return cast<Return>(this)->successors();
default:
return std::nullopt;
return {};
}
}

Expand Down
4 changes: 2 additions & 2 deletions clang/include/clang/Analysis/AnyCall.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class AnyCall {
/// \returns formal parameters for direct calls (including virtual calls)
ArrayRef<ParmVarDecl *> parameters() const {
if (!D)
return std::nullopt;
return {};

if (const auto *FD = dyn_cast<FunctionDecl>(D)) {
return FD->parameters();
Expand All @@ -152,7 +152,7 @@ class AnyCall {
} else if (const auto *BD = dyn_cast<BlockDecl>(D)) {
return BD->parameters();
} else {
return std::nullopt;
return {};
}
}

Expand Down
6 changes: 2 additions & 4 deletions clang/include/clang/Basic/TargetInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -1858,11 +1858,9 @@ class TargetInfo : public TransferrableTargetInfo,
}
virtual ArrayRef<const char *> getGCCRegNames() const = 0;
virtual ArrayRef<GCCRegAlias> getGCCRegAliases() const = 0;
virtual ArrayRef<AddlRegName> getGCCAddlRegNames() const {
return std::nullopt;
}
virtual ArrayRef<AddlRegName> getGCCAddlRegNames() const { return {}; }

private:
private:
// Assert the values for the fractional and integral bits for each fixed point
// type follow the restrictions given in clause 6.2.6.3 of N1169.
void CheckFixedPointBits() const;
Expand Down
6 changes: 2 additions & 4 deletions clang/include/clang/Driver/Job.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,7 @@ class Command {
Command(const Action &Source, const Tool &Creator,
ResponseFileSupport ResponseSupport, const char *Executable,
const llvm::opt::ArgStringList &Arguments, ArrayRef<InputInfo> Inputs,
ArrayRef<InputInfo> Outputs = std::nullopt,
const char *PrependArg = nullptr);
ArrayRef<InputInfo> Outputs = {}, const char *PrependArg = nullptr);
// FIXME: This really shouldn't be copyable, but is currently copied in some
// error handling in Driver::generateCompilationDiagnostics.
Command(const Command &) = default;
Expand Down Expand Up @@ -245,8 +244,7 @@ class CC1Command : public Command {
CC1Command(const Action &Source, const Tool &Creator,
ResponseFileSupport ResponseSupport, const char *Executable,
const llvm::opt::ArgStringList &Arguments,
ArrayRef<InputInfo> Inputs,
ArrayRef<InputInfo> Outputs = std::nullopt,
ArrayRef<InputInfo> Inputs, ArrayRef<InputInfo> Outputs = {},
const char *PrependArg = nullptr);

void Print(llvm::raw_ostream &OS, const char *Terminator, bool Quote,
Expand Down
4 changes: 2 additions & 2 deletions clang/include/clang/Frontend/ASTUnit.h
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,7 @@ class ASTUnit {
bool StorePreamblesInMemory = false,
StringRef PreambleStoragePath = StringRef(), bool OnlyLocalDecls = false,
CaptureDiagsKind CaptureDiagnostics = CaptureDiagsKind::None,
ArrayRef<RemappedFile> RemappedFiles = std::nullopt,
ArrayRef<RemappedFile> RemappedFiles = {},
bool RemappedFilesKeepOriginalName = true,
unsigned PrecompilePreambleAfterNParses = 0,
TranslationUnitKind TUKind = TU_Complete,
Expand Down Expand Up @@ -864,7 +864,7 @@ class ASTUnit {
/// \returns True if a failure occurred that causes the ASTUnit not to
/// contain any translation-unit information, false otherwise.
bool Reparse(std::shared_ptr<PCHContainerOperations> PCHContainerOps,
ArrayRef<RemappedFile> RemappedFiles = std::nullopt,
ArrayRef<RemappedFile> RemappedFiles = {},
IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS = nullptr);

/// Free data that will be re-generated on the next parse.
Expand Down
6 changes: 3 additions & 3 deletions clang/include/clang/Lex/Preprocessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ class Preprocessor {
getActiveModuleMacros(Preprocessor &PP, const IdentifierInfo *II) const {
if (auto *Info = getModuleInfo(PP, II))
return Info->ActiveModuleMacros;
return std::nullopt;
return {};
}

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

void setOverriddenMacros(Preprocessor &PP,
Expand Down Expand Up @@ -1444,7 +1444,7 @@ class Preprocessor {
auto I = LeafModuleMacros.find(II);
if (I != LeafModuleMacros.end())
return I->second;
return std::nullopt;
return {};
}

/// Get the list of submodules that we're currently building.
Expand Down
7 changes: 3 additions & 4 deletions clang/include/clang/Sema/CodeCompleteConsumer.h
Original file line number Diff line number Diff line change
Expand Up @@ -375,12 +375,11 @@ class CodeCompletionContext {
public:
/// Construct a new code-completion context of the given kind.
CodeCompletionContext(Kind CCKind)
: CCKind(CCKind), IsUsingDeclaration(false), SelIdents(std::nullopt) {}
: CCKind(CCKind), IsUsingDeclaration(false), SelIdents() {}

/// Construct a new code-completion context of the given kind.
CodeCompletionContext(
Kind CCKind, QualType T,
ArrayRef<const IdentifierInfo *> SelIdents = std::nullopt)
CodeCompletionContext(Kind CCKind, QualType T,
ArrayRef<const IdentifierInfo *> SelIdents = {})
: CCKind(CCKind), IsUsingDeclaration(false), SelIdents(SelIdents) {
if (CCKind == CCC_DotMemberAccess || CCKind == CCC_ArrowMemberAccess ||
CCKind == CCC_ObjCPropertyAccess || CCKind == CCC_ObjCClassMessage ||
Expand Down
5 changes: 2 additions & 3 deletions clang/include/clang/Sema/Overload.h
Original file line number Diff line number Diff line change
Expand Up @@ -1206,9 +1206,8 @@ class Sema;

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

Expand Down
Loading
Loading