[AST] Use std::nullopt instead of None (NFC)

This patch mechanically replaces None with std::nullopt where the
compiler would warn if None were deprecated.  The intent is to reduce
the amount of manual work required in migrating from Optional to
std::optional.

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
This commit is contained in:
Kazu Hirata 2022-12-03 11:13:41 -08:00
parent 8595f2e54d
commit e31564afc3
39 changed files with 152 additions and 150 deletions

View File

@ -2293,7 +2293,7 @@ public:
Optional<CharUnits> getTypeSizeInCharsIfKnown(QualType Ty) const {
if (Ty->isIncompleteType() || Ty->isDependentType())
return None;
return std::nullopt;
return getTypeSizeInChars(Ty);
}

View File

@ -70,7 +70,7 @@ public:
if (Pos != ImportErrors.end())
return Pos->second;
else
return None;
return std::nullopt;
}
void setImportDeclError(Decl *To, ASTImportError Error) {

View File

@ -80,7 +80,7 @@ public:
ArrayRef<T> copyArray(ArrayRef<T> Source) {
if (!Source.empty())
return Source.copy(Allocator);
return None;
return std::nullopt;
}
ParagraphComment *actOnParagraphComment(

View File

@ -108,11 +108,10 @@ public:
friend class ASTNodeImporter;
friend TrailingObjects;
static FriendDecl *Create(ASTContext &C, DeclContext *DC,
SourceLocation L, FriendUnion Friend_,
static FriendDecl *
Create(ASTContext &C, DeclContext *DC, SourceLocation L, FriendUnion Friend_,
SourceLocation FriendL,
ArrayRef<TemplateParameterList*> FriendTypeTPLists
= None);
ArrayRef<TemplateParameterList *> FriendTypeTPLists = std::nullopt);
static FriendDecl *CreateDeserialized(ASTContext &C, unsigned ID,
unsigned FriendTypeNumTPLists);

View File

@ -389,9 +389,8 @@ public:
/// Sets the method's parameters and selector source locations.
/// If the method is implicit (not coming from source) \p SelLocs is
/// ignored.
void setMethodParams(ASTContext &C,
ArrayRef<ParmVarDecl*> Params,
ArrayRef<SourceLocation> SelLocs = llvm::None);
void setMethodParams(ASTContext &C, ArrayRef<ParmVarDecl *> Params,
ArrayRef<SourceLocation> SelLocs = std::nullopt);
// Iterator access to parameter types.
struct GetTypeFn {

View File

@ -34,7 +34,7 @@ template <typename U> class OMPDeclarativeDirective : public U {
/// Get the clauses storage.
MutableArrayRef<OMPClause *> getClauses() {
if (!Data)
return llvm::None;
return std::nullopt;
return Data->getClauses();
}
@ -90,7 +90,7 @@ public:
ArrayRef<OMPClause *> clauses() const {
if (!Data)
return llvm::None;
return std::nullopt;
return Data->getClauses();
}
};

View File

@ -1245,14 +1245,11 @@ class TemplateTypeParmDecl final : public TypeDecl,
NumExpanded(NumExpanded.value_or(0)) {}
public:
static TemplateTypeParmDecl *Create(const ASTContext &C, DeclContext *DC,
SourceLocation KeyLoc,
SourceLocation NameLoc,
unsigned D, unsigned P,
IdentifierInfo *Id, bool Typename,
bool ParameterPack,
bool HasTypeConstraint = false,
Optional<unsigned> NumExpanded = None);
static TemplateTypeParmDecl *
Create(const ASTContext &C, DeclContext *DC, SourceLocation KeyLoc,
SourceLocation NameLoc, unsigned D, unsigned P, IdentifierInfo *Id,
bool Typename, bool ParameterPack, bool HasTypeConstraint = false,
Optional<unsigned> NumExpanded = std::nullopt);
static TemplateTypeParmDecl *CreateDeserialized(const ASTContext &C,
unsigned ID);
static TemplateTypeParmDecl *CreateDeserialized(const ASTContext &C,
@ -3453,7 +3450,7 @@ inline Optional<unsigned> getExpandedPackSize(const NamedDecl *Param) {
return TTP->getNumExpansionTemplateParameters();
}
return None;
return std::nullopt;
}
/// Internal helper used by Subst* nodes to retrieve the parameter list

View File

@ -2273,13 +2273,13 @@ public:
/// If the result is not-None, it will never wrap a nullptr.
Optional<Expr *> getArraySize() {
if (!isArray())
return None;
return std::nullopt;
if (auto *Result =
cast_or_null<Expr>(getTrailingObjects<Stmt *>()[arraySizeOffset()]))
return Result;
return None;
return std::nullopt;
}
/// This might return None even if isArray() returns true,
@ -2287,13 +2287,13 @@ public:
/// If the result is not-None, it will never wrap a nullptr.
Optional<const Expr *> getArraySize() const {
if (!isArray())
return None;
return std::nullopt;
if (auto *Result =
cast_or_null<Expr>(getTrailingObjects<Stmt *>()[arraySizeOffset()]))
return Result;
return None;
return std::nullopt;
}
unsigned getNumPlacementArgs() const {
@ -4116,7 +4116,7 @@ public:
if (NumExpansions)
return NumExpansions - 1;
return None;
return std::nullopt;
}
SourceLocation getBeginLoc() const LLVM_READONLY {
@ -4201,11 +4201,11 @@ class SizeOfPackExpr final
: Expr(SizeOfPackExprClass, Empty), Length(NumPartialArgs) {}
public:
static SizeOfPackExpr *Create(ASTContext &Context, SourceLocation OperatorLoc,
NamedDecl *Pack, SourceLocation PackLoc,
SourceLocation RParenLoc,
Optional<unsigned> Length = None,
ArrayRef<TemplateArgument> PartialArgs = None);
static SizeOfPackExpr *
Create(ASTContext &Context, SourceLocation OperatorLoc, NamedDecl *Pack,
SourceLocation PackLoc, SourceLocation RParenLoc,
Optional<unsigned> Length = std::nullopt,
ArrayRef<TemplateArgument> PartialArgs = std::nullopt);
static SizeOfPackExpr *CreateDeserialized(ASTContext &Context,
unsigned NumPartialArgs);
@ -4316,7 +4316,7 @@ public:
Optional<unsigned> getPackIndex() const {
if (PackIndex == 0)
return None;
return std::nullopt;
return PackIndex - 1;
}
@ -4681,7 +4681,7 @@ public:
Optional<unsigned> getNumExpansions() const {
if (NumExpansions)
return NumExpansions - 1;
return None;
return std::nullopt;
}
SourceLocation getBeginLoc() const LLVM_READONLY {

View File

@ -362,7 +362,8 @@ public:
ObjCDictionaryElement getKeyValueElement(unsigned Index) const {
assert((Index < NumElements) && "Arg access out of range!");
const KeyValuePair &KV = getTrailingObjects<KeyValuePair>()[Index];
ObjCDictionaryElement Result = { KV.Key, KV.Value, SourceLocation(), None };
ObjCDictionaryElement Result = {KV.Key, KV.Value, SourceLocation(),
std::nullopt};
if (HasPackExpansions) {
const ExpansionData &Expansion =
getTrailingObjects<ExpansionData>()[Index];

View File

@ -5838,14 +5838,14 @@ public:
return const_component_lists_iterator(
getUniqueDeclsRef(), getDeclNumListsRef(), getComponentListSizesRef(),
getComponentsRef(), SupportsMapper,
SupportsMapper ? getUDMapperRefs() : llvm::None);
SupportsMapper ? getUDMapperRefs() : std::nullopt);
}
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, llvm::None);
SupportsMapper, std::nullopt);
}
const_component_lists_range component_lists() const {
return {component_lists_begin(), component_lists_end()};
@ -5858,7 +5858,7 @@ public:
return const_component_lists_iterator(
VD, getUniqueDeclsRef(), getDeclNumListsRef(),
getComponentListSizesRef(), getComponentsRef(), SupportsMapper,
SupportsMapper ? getUDMapperRefs() : llvm::None);
SupportsMapper ? getUDMapperRefs() : std::nullopt);
}
const_component_lists_iterator decl_component_lists_end() const {
return component_lists_end();

View File

@ -277,7 +277,7 @@ class OMPExecutableDirective : public Stmt {
/// Get the clauses storage.
MutableArrayRef<OMPClause *> getClauses() {
if (!Data)
return llvm::None;
return std::nullopt;
return Data->getClauses();
}
@ -571,7 +571,7 @@ public:
ArrayRef<OMPClause *> clauses() const {
if (!Data)
return llvm::None;
return std::nullopt;
return Data->getClauses();
}

View File

@ -233,7 +233,9 @@ public:
TemplateArgument(TemplateName, bool) = delete;
static TemplateArgument getEmptyPack() { return TemplateArgument(None); }
static TemplateArgument getEmptyPack() {
return TemplateArgument(std::nullopt);
}
/// Create a new template argument pack by copying the given set of
/// template arguments.

View File

@ -397,7 +397,7 @@ public:
Optional<unsigned> getPackIndex() const {
if (Bits.Data == 0)
return None;
return std::nullopt;
return Bits.Data - 1;
}

View File

@ -5113,7 +5113,7 @@ public:
Optional<unsigned> getPackIndex() const {
if (SubstTemplateTypeParmTypeBits.PackIndex == 0)
return None;
return std::nullopt;
return SubstTemplateTypeParmTypeBits.PackIndex - 1;
}
@ -5855,7 +5855,7 @@ public:
Optional<unsigned> getNumExpansions() const {
if (PackExpansionTypeBits.NumExpansions)
return PackExpansionTypeBits.NumExpansions - 1;
return None;
return std::nullopt;
}
bool isSugared() const { return false; }

View File

@ -771,9 +771,9 @@ canonicalizeImmediatelyDeclaredConstraint(const ASTContext &C, Expr *IDC,
if (auto *OrigFold = dyn_cast<CXXFoldExpr>(IDC))
NewIDC = new (C) CXXFoldExpr(
OrigFold->getType(), /*Callee*/nullptr, SourceLocation(), NewIDC,
OrigFold->getType(), /*Callee*/ nullptr, SourceLocation(), NewIDC,
BinaryOperatorKind::BO_LAnd, SourceLocation(), /*RHS=*/nullptr,
SourceLocation(), /*NumExpansions=*/None);
SourceLocation(), /*NumExpansions=*/std::nullopt);
return NewIDC;
}
@ -797,12 +797,13 @@ ASTContext::getCanonicalTemplateTemplateParmDecl(
PEnd = Params->end();
P != PEnd; ++P) {
if (const auto *TTP = dyn_cast<TemplateTypeParmDecl>(*P)) {
TemplateTypeParmDecl *NewTTP = TemplateTypeParmDecl::Create(*this,
getTranslationUnitDecl(), SourceLocation(), SourceLocation(),
TemplateTypeParmDecl *NewTTP = TemplateTypeParmDecl::Create(
*this, getTranslationUnitDecl(), SourceLocation(), SourceLocation(),
TTP->getDepth(), TTP->getIndex(), nullptr, false,
TTP->isParameterPack(), TTP->hasTypeConstraint(),
TTP->isExpandedParameterPack() ?
llvm::Optional<unsigned>(TTP->getNumExpansionParameters()) : None);
TTP->isExpandedParameterPack()
? llvm::Optional<unsigned>(TTP->getNumExpansionParameters())
: std::nullopt);
if (const auto *TC = TTP->getTypeConstraint()) {
QualType ParamAsArgument(NewTTP->getTypeForDecl(), 0);
Expr *NewIDC = canonicalizeImmediatelyDeclaredConstraint(
@ -1139,7 +1140,7 @@ ASTContext::getModulesWithMergedDefinition(const NamedDecl *Def) {
auto MergedIt =
MergedDefModules.find(cast<NamedDecl>(Def->getCanonicalDecl()));
if (MergedIt == MergedDefModules.end())
return None;
return std::nullopt;
return MergedIt->second;
}
@ -1197,7 +1198,7 @@ void ASTContext::addLazyModuleInitializers(Module *M, ArrayRef<uint32_t> IDs) {
ArrayRef<Decl *> ASTContext::getModuleInitializers(Module *M) {
auto It = ModuleInitializers.find(M);
if (It == ModuleInitializers.end())
return None;
return std::nullopt;
auto *Inits = It->second;
Inits->resolve(*this);
@ -2743,7 +2744,7 @@ getSubobjectSizeInBits(const FieldDecl *Field, const ASTContext &Context) {
bool IsBitIntType = Field->getType()->isBitIntType();
if (!Field->getType()->isReferenceType() && !IsBitIntType &&
!Context.hasUniqueObjectRepresentations(Field->getType()))
return llvm::None;
return std::nullopt;
int64_t FieldSizeInBits =
Context.toBits(Context.getTypeSizeInChars(Field->getType()));
@ -2752,14 +2753,14 @@ getSubobjectSizeInBits(const FieldDecl *Field, const ASTContext &Context) {
if (IsBitIntType) {
if ((unsigned)BitfieldSize >
cast<BitIntType>(Field->getType())->getNumBits())
return llvm::None;
return std::nullopt;
} else if (BitfieldSize > FieldSizeInBits) {
return llvm::None;
return std::nullopt;
}
FieldSizeInBits = BitfieldSize;
} else if (IsBitIntType &&
!Context.hasUniqueObjectRepresentations(Field->getType())) {
return llvm::None;
return std::nullopt;
}
return FieldSizeInBits;
}
@ -2777,11 +2778,11 @@ static llvm::Optional<int64_t> structSubobjectsHaveUniqueObjectRepresentations(
llvm::Optional<int64_t> SizeInBits =
getSubobjectSizeInBits(Subobject, Context);
if (!SizeInBits)
return llvm::None;
return std::nullopt;
if (*SizeInBits != 0) {
int64_t Offset = getSubobjectOffset(Subobject, Context, Layout);
if (Offset != CurOffsetInBits)
return llvm::None;
return std::nullopt;
CurOffsetInBits += *SizeInBits;
}
}
@ -2797,7 +2798,7 @@ structHasUniqueObjectRepresentations(const ASTContext &Context,
int64_t CurOffsetInBits = 0;
if (const auto *ClassDecl = dyn_cast<CXXRecordDecl>(RD)) {
if (ClassDecl->isDynamicClass())
return llvm::None;
return std::nullopt;
SmallVector<CXXRecordDecl *, 4> Bases;
for (const auto &Base : ClassDecl->bases()) {
@ -2814,7 +2815,7 @@ structHasUniqueObjectRepresentations(const ASTContext &Context,
structSubobjectsHaveUniqueObjectRepresentations(Bases, CurOffsetInBits,
Context, Layout);
if (!OffsetAfterBases)
return llvm::None;
return std::nullopt;
CurOffsetInBits = *OffsetAfterBases;
}
@ -2822,7 +2823,7 @@ structHasUniqueObjectRepresentations(const ASTContext &Context,
structSubobjectsHaveUniqueObjectRepresentations(
RD->fields(), CurOffsetInBits, Context, Layout);
if (!OffsetAfterFields)
return llvm::None;
return std::nullopt;
CurOffsetInBits = *OffsetAfterFields;
return CurOffsetInBits;
@ -5218,7 +5219,7 @@ TemplateArgument ASTContext::getInjectedTemplateArg(NamedDecl *Param) {
if (const auto *TTP = dyn_cast<TemplateTypeParmDecl>(Param)) {
QualType ArgType = getTypeDeclType(TTP);
if (TTP->isParameterPack())
ArgType = getPackExpansionType(ArgType, None);
ArgType = getPackExpansionType(ArgType, std::nullopt);
Arg = TemplateArgument(ArgType);
} else if (auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param)) {
@ -5235,8 +5236,8 @@ TemplateArgument ASTContext::getInjectedTemplateArg(NamedDecl *Param) {
Expr::getValueKindForType(NTTP->getType()), NTTP->getLocation());
if (NTTP->isParameterPack())
E = new (*this) PackExpansionExpr(DependentTy, E, NTTP->getLocation(),
None);
E = new (*this)
PackExpansionExpr(DependentTy, E, NTTP->getLocation(), std::nullopt);
Arg = TemplateArgument(E);
} else {
auto *TTP = cast<TemplateTemplateParmDecl>(Param);
@ -11923,7 +11924,7 @@ MangleContext *ASTContext::createDeviceMangleContext(const TargetInfo &T) {
[](ASTContext &, const NamedDecl *ND) -> llvm::Optional<unsigned> {
if (const auto *RD = dyn_cast<CXXRecordDecl>(ND))
return RD->getDeviceLambdaManglingNumber();
return llvm::None;
return std::nullopt;
},
/*IsAux=*/true);
case TargetCXXABI::Microsoft:

View File

@ -223,7 +223,7 @@ namespace clang {
template<typename T>
Expected<Optional<T>> import(Optional<T> From) {
if (!From)
return None;
return std::nullopt;
return import(*From);
}
@ -8544,7 +8544,7 @@ Optional<unsigned> ASTImporter::getFieldIndex(Decl *F) {
auto *Owner = dyn_cast<RecordDecl>(F->getDeclContext());
if (!Owner)
return None;
return std::nullopt;
unsigned Index = 0;
for (const auto *D : Owner->decls()) {
@ -8557,7 +8557,7 @@ Optional<unsigned> ASTImporter::getFieldIndex(Decl *F) {
llvm_unreachable("Field was not found in its parent context.");
return None;
return std::nullopt;
}
ASTImporter::FoundDeclsTy
@ -10022,7 +10022,7 @@ ASTImporter::getImportDeclErrorIfAny(Decl *FromD) const {
if (Pos != ImportDeclErrors.end())
return Pos->second;
else
return None;
return std::nullopt;
}
void ASTImporter::setImportDeclError(Decl *From, ASTImportError Error) {

View File

@ -2128,7 +2128,7 @@ StructuralEquivalenceContext::findUntaggedStructOrUnionIndex(RecordDecl *Anon) {
const auto *Owner = dyn_cast<RecordDecl>(Anon->getDeclContext());
if (!Owner)
return None;
return std::nullopt;
unsigned Index = 0;
for (const auto *D : Owner->noload_decls()) {

View File

@ -151,7 +151,7 @@ void OMPDeclareTargetDeclAttr::printPrettyPragma(
llvm::Optional<OMPDeclareTargetDeclAttr *>
OMPDeclareTargetDeclAttr::getActiveAttr(const ValueDecl *VD) {
if (!VD->hasAttrs())
return llvm::None;
return std::nullopt;
unsigned Level = 0;
OMPDeclareTargetDeclAttr *FoundAttr = nullptr;
for (auto *Attr : VD->specific_attrs<OMPDeclareTargetDeclAttr>()) {
@ -162,7 +162,7 @@ OMPDeclareTargetDeclAttr::getActiveAttr(const ValueDecl *VD) {
}
if (FoundAttr)
return FoundAttr;
return llvm::None;
return std::nullopt;
}
llvm::Optional<OMPDeclareTargetDeclAttr::MapTypeTy>
@ -170,7 +170,7 @@ OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(const ValueDecl *VD) {
llvm::Optional<OMPDeclareTargetDeclAttr *> ActiveAttr = getActiveAttr(VD);
if (ActiveAttr)
return ActiveAttr.value()->getMapType();
return llvm::None;
return std::nullopt;
}
llvm::Optional<OMPDeclareTargetDeclAttr::DevTypeTy>
@ -178,7 +178,7 @@ OMPDeclareTargetDeclAttr::getDeviceType(const ValueDecl *VD) {
llvm::Optional<OMPDeclareTargetDeclAttr *> ActiveAttr = getActiveAttr(VD);
if (ActiveAttr)
return ActiveAttr.value()->getDevType();
return llvm::None;
return std::nullopt;
}
llvm::Optional<SourceLocation>
@ -186,7 +186,7 @@ OMPDeclareTargetDeclAttr::getLocation(const ValueDecl *VD) {
llvm::Optional<OMPDeclareTargetDeclAttr *> ActiveAttr = getActiveAttr(VD);
if (ActiveAttr)
return ActiveAttr.value()->getRange().getBegin();
return llvm::None;
return std::nullopt;
}
namespace clang {

View File

@ -206,7 +206,7 @@ void DeclInfo::fill() {
IsInstanceMethod = false;
IsClassMethod = false;
IsVariadic = false;
ParamVars = None;
ParamVars = std::nullopt;
TemplateParameters = nullptr;
if (!CommentDecl) {

View File

@ -334,7 +334,7 @@ BlockCommandComment *Parser::parseBlockCommand() {
if (isTokBlockCommand()) {
// Block command ahead. We can't nest block commands, so pretend that this
// command has an empty argument.
ParagraphComment *Paragraph = S.actOnParagraphComment(None);
ParagraphComment *Paragraph = S.actOnParagraphComment(std::nullopt);
if (PC) {
S.actOnParamCommandFinish(PC, Paragraph);
return PC;
@ -376,7 +376,7 @@ BlockCommandComment *Parser::parseBlockCommand() {
ParagraphComment *Paragraph;
if (EmptyParagraph)
Paragraph = S.actOnParagraphComment(None);
Paragraph = S.actOnParagraphComment(std::nullopt);
else {
BlockContentComment *Block = parseParagraphOrBlockCommand();
// Since we have checked for a block command, we should have parsed a

View File

@ -37,7 +37,7 @@ clang::getComparisonCategoryForBuiltinCmp(QualType T) {
return CCT::StrongOrdering;
// TODO: Extend support for operator<=> to ObjC types.
return llvm::None;
return std::nullopt;
}
bool ComparisonCategoryInfo::ValueInfo::hasValidIntValue() const {

View File

@ -235,7 +235,7 @@ static Optional<Visibility> getVisibilityOf(const NamedDecl *D,
return getVisibilityFromAttr(A);
}
return None;
return std::nullopt;
}
LinkageInfo LinkageComputer::getLVForType(const Type &T,
@ -1194,11 +1194,11 @@ getExplicitVisibilityAux(const NamedDecl *ND,
const auto *TD = spec->getSpecializedTemplate()->getTemplatedDecl();
while (TD != nullptr) {
auto Vis = getVisibilityOf(TD, kind);
if (Vis != None)
if (Vis != std::nullopt)
return Vis;
TD = TD->getPreviousDecl();
}
return None;
return std::nullopt;
}
// Use the most recent declaration.
@ -1219,7 +1219,7 @@ getExplicitVisibilityAux(const NamedDecl *ND,
return getVisibilityOf(VTSD->getSpecializedTemplate()->getTemplatedDecl(),
kind);
return None;
return std::nullopt;
}
// Also handle function template specializations.
if (const auto *fn = dyn_cast<FunctionDecl>(ND)) {
@ -1236,14 +1236,14 @@ getExplicitVisibilityAux(const NamedDecl *ND,
if (InstantiatedFrom)
return getVisibilityOf(InstantiatedFrom, kind);
return None;
return std::nullopt;
}
// The visibility of a template is stored in the templated decl.
if (const auto *TD = dyn_cast<TemplateDecl>(ND))
return getVisibilityOf(TD->getTemplatedDecl(), kind);
return None;
return std::nullopt;
}
Optional<Visibility>
@ -5130,8 +5130,9 @@ IndirectFieldDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L,
IndirectFieldDecl *IndirectFieldDecl::CreateDeserialized(ASTContext &C,
unsigned ID) {
return new (C, ID) IndirectFieldDecl(C, nullptr, SourceLocation(),
DeclarationName(), QualType(), None);
return new (C, ID)
IndirectFieldDecl(C, nullptr, SourceLocation(), DeclarationName(),
QualType(), std::nullopt);
}
SourceRange EnumConstantDecl::getSourceRange() const {
@ -5362,7 +5363,7 @@ ImportDecl *ImportDecl::CreateDeserialized(ASTContext &C, unsigned ID,
ArrayRef<SourceLocation> ImportDecl::getIdentifierLocs() const {
if (!isImportComplete())
return None;
return std::nullopt;
const auto *StoredLocs = getTrailingObjects<SourceLocation>();
return llvm::makeArrayRef(StoredLocs,

View File

@ -3139,7 +3139,8 @@ UsingPackDecl *UsingPackDecl::Create(ASTContext &C, DeclContext *DC,
UsingPackDecl *UsingPackDecl::CreateDeserialized(ASTContext &C, unsigned ID,
unsigned NumExpansions) {
size_t Extra = additionalSizeToAlloc<NamedDecl *>(NumExpansions);
auto *Result = new (C, ID, Extra) UsingPackDecl(nullptr, nullptr, None);
auto *Result =
new (C, ID, Extra) UsingPackDecl(nullptr, nullptr, std::nullopt);
Result->NumExpansions = NumExpansions;
auto *Trail = Result->getTrailingObjects<NamedDecl *>();
for (unsigned I = 0; I != NumExpansions; ++I)
@ -3277,7 +3278,7 @@ DecompositionDecl *DecompositionDecl::CreateDeserialized(ASTContext &C,
size_t Extra = additionalSizeToAlloc<BindingDecl *>(NumBindings);
auto *Result = new (C, ID, Extra)
DecompositionDecl(C, nullptr, SourceLocation(), SourceLocation(),
QualType(), nullptr, StorageClass(), None);
QualType(), nullptr, StorageClass(), std::nullopt);
// Set up and clean out the bindings array.
Result->NumBindings = NumBindings;
auto *Trail = Result->getTrailingObjects<BindingDecl *>();

View File

@ -910,12 +910,12 @@ void ObjCMethodDecl::setMethodParams(ASTContext &C,
assert((!SelLocs.empty() || isImplicit()) &&
"No selector locs for non-implicit method");
if (isImplicit())
return setParamsAndSelLocs(C, Params, llvm::None);
return setParamsAndSelLocs(C, Params, std::nullopt);
setSelLocsKind(hasStandardSelectorLocs(getSelector(), SelLocs, Params,
DeclEndLoc));
if (getSelLocsKind() != SelLoc_NonStandard)
return setParamsAndSelLocs(C, Params, llvm::None);
return setParamsAndSelLocs(C, Params, std::nullopt);
setParamsAndSelLocs(C, Params, SelLocs);
}

View File

@ -30,7 +30,7 @@ OMPThreadPrivateDecl *OMPThreadPrivateDecl::Create(ASTContext &C,
SourceLocation L,
ArrayRef<Expr *> VL) {
auto *D = OMPDeclarativeDirective::createDirective<OMPThreadPrivateDecl>(
C, DC, llvm::None, VL.size(), L);
C, DC, std::nullopt, VL.size(), L);
D->setVars(VL);
return D;
}

View File

@ -656,9 +656,9 @@ TemplateTypeParmDecl::Create(const ASTContext &C, DeclContext *DC,
TemplateTypeParmDecl *
TemplateTypeParmDecl::CreateDeserialized(const ASTContext &C, unsigned ID) {
return new (C, ID) TemplateTypeParmDecl(nullptr, SourceLocation(),
SourceLocation(), nullptr, false,
false, None);
return new (C, ID)
TemplateTypeParmDecl(nullptr, SourceLocation(), SourceLocation(), nullptr,
false, false, std::nullopt);
}
TemplateTypeParmDecl *
@ -666,8 +666,8 @@ TemplateTypeParmDecl::CreateDeserialized(const ASTContext &C, unsigned ID,
bool HasTypeConstraint) {
return new (C, ID,
additionalSizeToAlloc<TypeConstraint>(HasTypeConstraint ? 1 : 0))
TemplateTypeParmDecl(nullptr, SourceLocation(), SourceLocation(),
nullptr, false, HasTypeConstraint, None);
TemplateTypeParmDecl(nullptr, SourceLocation(), SourceLocation(), nullptr,
false, HasTypeConstraint, std::nullopt);
}
SourceLocation TemplateTypeParmDecl::getDefaultArgumentLoc() const {
@ -781,12 +781,12 @@ NonTypeTemplateParmDecl::CreateDeserialized(ASTContext &C, unsigned ID,
unsigned NumExpandedTypes,
bool HasTypeConstraint) {
auto *NTTP =
new (C, ID, additionalSizeToAlloc<std::pair<QualType, TypeSourceInfo *>,
Expr *>(
new (C, ID,
additionalSizeToAlloc<std::pair<QualType, TypeSourceInfo *>, Expr *>(
NumExpandedTypes, HasTypeConstraint ? 1 : 0))
NonTypeTemplateParmDecl(nullptr, SourceLocation(), SourceLocation(),
0, 0, nullptr, QualType(), nullptr, None,
None);
0, 0, nullptr, QualType(), nullptr,
std::nullopt, std::nullopt);
NTTP->NumExpandedTypes = NumExpandedTypes;
return NTTP;
}
@ -854,7 +854,7 @@ TemplateTemplateParmDecl::CreateDeserialized(ASTContext &C, unsigned ID,
auto *TTP =
new (C, ID, additionalSizeToAlloc<TemplateParameterList *>(NumExpansions))
TemplateTemplateParmDecl(nullptr, SourceLocation(), 0, 0, nullptr,
nullptr, None);
nullptr, std::nullopt);
TTP->NumExpandedParams = NumExpansions;
return TTP;
}

View File

@ -647,7 +647,7 @@ std::string SYCLUniqueStableNameExpr::ComputeName(ASTContext &Context,
const NamedDecl *ND) -> llvm::Optional<unsigned> {
if (const auto *RD = dyn_cast<CXXRecordDecl>(ND))
return RD->getDeviceLambdaManglingNumber();
return llvm::None;
return std::nullopt;
};
std::unique_ptr<MangleContext> Ctx{ItaniumMangleContext::create(
@ -4533,7 +4533,8 @@ DesignatedInitUpdateExpr::DesignatedInitUpdateExpr(const ASTContext &C,
OK_Ordinary) {
BaseAndUpdaterExprs[0] = baseExpr;
InitListExpr *ILE = new (C) InitListExpr(C, lBraceLoc, None, rBraceLoc);
InitListExpr *ILE =
new (C) InitListExpr(C, lBraceLoc, std::nullopt, rBraceLoc);
ILE->setType(baseExpr->getType());
BaseAndUpdaterExprs[1] = ILE;

View File

@ -5680,7 +5680,7 @@ static Optional<DynamicType> ComputeDynamicType(EvalInfo &Info, const Expr *E,
// meaningful dynamic type. (We consider objects of non-class type to have no
// dynamic type.)
if (!checkDynamicType(Info, E, This, AK, true))
return None;
return std::nullopt;
// Refuse to compute a dynamic type in the presence of virtual bases. This
// shouldn't happen other than in constant-folding situations, since literal
@ -5692,7 +5692,7 @@ static Optional<DynamicType> ComputeDynamicType(EvalInfo &Info, const Expr *E,
This.Designator.MostDerivedType->getAsCXXRecordDecl();
if (!Class || Class->getNumVBases()) {
Info.FFDiag(E);
return None;
return std::nullopt;
}
// FIXME: For very deep class hierarchies, it might be beneficial to use a
@ -5725,7 +5725,7 @@ static Optional<DynamicType> ComputeDynamicType(EvalInfo &Info, const Expr *E,
// 'This', so that object has not yet begun its period of construction and
// any polymorphic operation on it results in undefined behavior.
Info.FFDiag(E);
return None;
return std::nullopt;
}
/// Perform virtual dispatch.
@ -6753,13 +6753,13 @@ static Optional<DynAlloc *> CheckDeleteKind(EvalInfo &Info, const Expr *E,
<< PointerAsString();
if (Pointer.Base)
NoteLValueLocation(Info, Pointer.Base);
return None;
return std::nullopt;
}
Optional<DynAlloc *> Alloc = Info.lookupDynamicAlloc(DA);
if (!Alloc) {
Info.FFDiag(E, diag::note_constexpr_double_delete);
return None;
return std::nullopt;
}
QualType AllocType = Pointer.Base.getDynamicAllocType();
@ -6767,7 +6767,7 @@ static Optional<DynAlloc *> CheckDeleteKind(EvalInfo &Info, const Expr *E,
Info.FFDiag(E, diag::note_constexpr_new_delete_mismatch)
<< DeallocKind << (*Alloc)->getKind() << AllocType;
NoteLValueLocation(Info, Pointer.Base);
return None;
return std::nullopt;
}
bool Subobject = false;
@ -6781,7 +6781,7 @@ static Optional<DynAlloc *> CheckDeleteKind(EvalInfo &Info, const Expr *E,
if (Subobject) {
Info.FFDiag(E, diag::note_constexpr_delete_subobject)
<< PointerAsString() << Pointer.Designator.isOnePastTheEnd();
return None;
return std::nullopt;
}
return Alloc;
@ -7028,7 +7028,7 @@ public:
CharUnits DstSize = Info.Ctx.getTypeSizeInChars(BCE->getType());
APValueToBufferConverter Converter(Info, DstSize, BCE);
if (!Converter.visit(Src, BCE->getSubExpr()->getType()))
return None;
return std::nullopt;
return Converter.Buffer;
}
};
@ -7050,14 +7050,14 @@ class BufferToAPValueConverter {
Info.FFDiag(BCE->getBeginLoc(),
diag::note_constexpr_bit_cast_unsupported_type)
<< Ty;
return None;
return std::nullopt;
}
std::nullopt_t unrepresentableValue(QualType Ty, const APSInt &Val) {
Info.FFDiag(BCE->getBeginLoc(),
diag::note_constexpr_bit_cast_unrepresentable_value)
<< Ty << toString(Val, /*Radix=*/10);
return None;
return std::nullopt;
}
Optional<APValue> visit(const BuiltinType *T, CharUnits Offset,
@ -7097,7 +7097,7 @@ class BufferToAPValueConverter {
Info.FFDiag(BCE->getExprLoc(),
diag::note_constexpr_bit_cast_indet_dest)
<< DisplayType << Info.Ctx.getLangOpts().CharIsSigned;
return None;
return std::nullopt;
}
return APValue::IndeterminateValue();
@ -7152,7 +7152,7 @@ class BufferToAPValueConverter {
Optional<APValue> SubObj = visitType(
BS.getType(), Layout.getBaseClassOffset(BaseDecl) + Offset);
if (!SubObj)
return None;
return std::nullopt;
ResultVal.getStructBase(I) = *SubObj;
}
}
@ -7165,7 +7165,7 @@ class BufferToAPValueConverter {
if (FD->isBitField()) {
Info.FFDiag(BCE->getBeginLoc(),
diag::note_constexpr_bit_cast_unsupported_bitfield);
return None;
return std::nullopt;
}
uint64_t FieldOffsetBits = Layout.getFieldOffset(FieldIdx);
@ -7177,7 +7177,7 @@ class BufferToAPValueConverter {
QualType FieldTy = FD->getType();
Optional<APValue> SubObj = visitType(FieldTy, FieldOffset);
if (!SubObj)
return None;
return std::nullopt;
ResultVal.getStructField(FieldIdx) = *SubObj;
++FieldIdx;
}
@ -7205,7 +7205,7 @@ class BufferToAPValueConverter {
Optional<APValue> ElementValue =
visitType(Ty->getElementType(), Offset + I * ElementWidth);
if (!ElementValue)
return None;
return std::nullopt;
ArrayValue.getArrayInitializedElt(I) = std::move(*ElementValue);
}
@ -10571,7 +10571,7 @@ static llvm::Optional<APValue> handleVectorUnaryOperator(ASTContext &Ctx,
}
default:
// FIXME: Implement the rest of the unary operators.
return llvm::None;
return std::nullopt;
}
}
@ -15943,7 +15943,7 @@ Optional<llvm::APSInt> Expr::getIntegerConstantExpr(const ASTContext &Ctx,
bool isEvaluated) const {
if (isValueDependent()) {
// Expression evaluator can't succeed on a dependent expression.
return None;
return std::nullopt;
}
APSInt Value;
@ -15951,11 +15951,11 @@ Optional<llvm::APSInt> Expr::getIntegerConstantExpr(const ASTContext &Ctx,
if (Ctx.getLangOpts().CPlusPlus11) {
if (EvaluateCPlusPlus11IntegralConstantExpr(Ctx, this, &Value, Loc))
return Value;
return None;
return std::nullopt;
}
if (!isIntegerConstantExpr(Ctx, Loc))
return None;
return std::nullopt;
// The only possible side-effects here are due to UB discovered in the
// evaluation (for instance, INT_MAX + 1). In such a case, we are still

View File

@ -32,7 +32,7 @@ ExternalASTSource::~ExternalASTSource() = default;
llvm::Optional<ASTSourceDescriptor>
ExternalASTSource::getSourceDescriptor(unsigned ID) {
return None;
return std::nullopt;
}
ExternalASTSource::ExtKind

View File

@ -740,7 +740,7 @@ ConversionSpecifier::getStandardSpecifier() const {
switch (getKind()) {
default:
return None;
return std::nullopt;
case DArg:
NewKind = dArg;
break;
@ -1041,7 +1041,7 @@ Optional<LengthModifier> FormatSpecifier::getCorrectedLengthModifier() const {
}
}
return None;
return std::nullopt;
}
bool FormatSpecifier::namedTypeToLengthModifier(QualType QT,

View File

@ -96,7 +96,7 @@ Optional<bool> areDenseMapKeysEqualSpecialValues(T LHS, T RHS) {
if (LHSTombstone || RHSTombstone)
return LHSTombstone && RHSTombstone;
return None;
return std::nullopt;
}
template<>

View File

@ -6560,7 +6560,7 @@ ItaniumMangleContext *ItaniumMangleContext::create(ASTContext &Context,
return new ItaniumMangleContextImpl(
Context, Diags,
[](ASTContext &, const NamedDecl *) -> llvm::Optional<unsigned> {
return llvm::None;
return std::nullopt;
},
IsAux);
}

View File

@ -95,7 +95,7 @@ class LinkageComputer {
LVComputationKind Kind) const {
auto Iter = CachedLinkageInfo.find(makeCacheKey(ND, Kind));
if (Iter == CachedLinkageInfo.end())
return None;
return std::nullopt;
return Iter->second;
}

View File

@ -376,7 +376,7 @@ public:
void mangleBits(llvm::APInt Number);
void mangleTagTypeKind(TagTypeKind TK);
void mangleArtificialTagType(TagTypeKind TK, StringRef UnqualifiedName,
ArrayRef<StringRef> NestedNames = None);
ArrayRef<StringRef> NestedNames = std::nullopt);
void mangleAddressSpaceType(QualType T, Qualifiers Quals, SourceRange Range);
void mangleType(QualType T, SourceRange Range,
QualifierMangleMode QMM = QMM_Mangle);

View File

@ -149,7 +149,7 @@ Optional<NSAPI::NSArrayMethodKind> NSAPI::getNSArrayMethodKind(Selector Sel) {
return MK;
}
return None;
return std::nullopt;
}
Selector NSAPI::getNSDictionarySelector(
@ -251,7 +251,7 @@ NSAPI::getNSDictionaryMethodKind(Selector Sel) {
return MK;
}
return None;
return std::nullopt;
}
Selector NSAPI::getNSSetSelector(NSSetMethodKind MK) const {
@ -308,7 +308,7 @@ NSAPI::getNSSetMethodKind(Selector Sel) {
return MK;
}
return None;
return std::nullopt;
}
Selector NSAPI::getNSNumberLiteralSelector(NSNumberLiteralMethodKind MK,
@ -371,14 +371,14 @@ NSAPI::getNSNumberLiteralMethodKind(Selector Sel) const {
return MK;
}
return None;
return std::nullopt;
}
Optional<NSAPI::NSNumberLiteralMethodKind>
NSAPI::getNSNumberFactoryMethodKind(QualType T) const {
const BuiltinType *BT = T->getAs<BuiltinType>();
if (!BT)
return None;
return std::nullopt;
const TypedefType *TDT = T->getAs<TypedefType>();
if (TDT) {
@ -496,7 +496,7 @@ NSAPI::getNSNumberFactoryMethodKind(QualType T) const {
break;
}
return None;
return std::nullopt;
}
/// Returns true if \param T is a typedef of "BOOL" in objective-c.

View File

@ -1003,7 +1003,7 @@ bool IfStmt::isObjCAvailabilityCheck() const {
Optional<Stmt *> IfStmt::getNondiscardedCase(const ASTContext &Ctx) {
if (!isConstexpr() || getCond()->isValueDependent())
return None;
return std::nullopt;
return !getCond()->EvaluateKnownConstInt(Ctx) ? getElse() : getThen();
}
@ -1012,7 +1012,7 @@ IfStmt::getNondiscardedCase(const ASTContext &Ctx) const {
if (Optional<Stmt *> Result =
const_cast<IfStmt *>(this)->getNondiscardedCase(Ctx))
return *Result;
return None;
return std::nullopt;
}
ForStmt::ForStmt(const ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar,

View File

@ -517,7 +517,7 @@ OMPSectionDirective *OMPSectionDirective::Create(const ASTContext &C,
Stmt *AssociatedStmt,
bool HasCancel) {
auto *Dir =
createDirective<OMPSectionDirective>(C, llvm::None, AssociatedStmt,
createDirective<OMPSectionDirective>(C, std::nullopt, AssociatedStmt,
/*NumChildren=*/0, StartLoc, EndLoc);
Dir->setHasCancel(HasCancel);
return Dir;
@ -550,7 +550,7 @@ OMPMasterDirective *OMPMasterDirective::Create(const ASTContext &C,
SourceLocation StartLoc,
SourceLocation EndLoc,
Stmt *AssociatedStmt) {
return createDirective<OMPMasterDirective>(C, llvm::None, AssociatedStmt,
return createDirective<OMPMasterDirective>(C, std::nullopt, AssociatedStmt,
/*NumChildren=*/0, StartLoc,
EndLoc);
}

View File

@ -276,7 +276,7 @@ Optional<unsigned> TemplateArgument::getNumTemplateExpansions() const {
if (TemplateArg.NumExpansions)
return TemplateArg.NumExpansions - 1;
return None;
return std::nullopt;
}
QualType TemplateArgument::getNonTypeTemplateArgumentType() const {

View File

@ -1527,23 +1527,23 @@ Optional<ArrayRef<QualType>> Type::getObjCSubstitutions(
// substitution to do.
dcTypeParams = dcClassDecl->getTypeParamList();
if (!dcTypeParams)
return None;
return std::nullopt;
} else {
// If we are in neither a class nor a category, there's no
// substitution to perform.
dcCategoryDecl = dyn_cast<ObjCCategoryDecl>(dc);
if (!dcCategoryDecl)
return None;
return std::nullopt;
// If the category does not have any type parameters, there's no
// substitution to do.
dcTypeParams = dcCategoryDecl->getTypeParamList();
if (!dcTypeParams)
return None;
return std::nullopt;
dcClassDecl = dcCategoryDecl->getClassInterface();
if (!dcClassDecl)
return None;
return std::nullopt;
}
assert(dcTypeParams && "No substitutions to perform");
assert(dcClassDecl && "No class context");
@ -4153,7 +4153,7 @@ Type::getNullability(const ASTContext &Context) const {
Type = AT->getEquivalentType();
}
return None;
return std::nullopt;
}
bool Type::canHaveNullability(bool ResultIfUnknown) const {
@ -4294,7 +4294,7 @@ AttributedType::getImmediateNullability() const {
return NullabilityKind::Unspecified;
if (getAttrKind() == attr::TypeNullableResult)
return NullabilityKind::NullableResult;
return None;
return std::nullopt;
}
Optional<NullabilityKind> AttributedType::stripOuterNullability(QualType &T) {
@ -4309,7 +4309,7 @@ Optional<NullabilityKind> AttributedType::stripOuterNullability(QualType &T) {
}
}
return None;
return std::nullopt;
}
bool Type::isBlockCompatibleObjCPointerType(ASTContext &ctx) const {