aboutsummaryrefslogtreecommitdiff
path: root/clang-tools-extra/clang-tidy/readability
diff options
context:
space:
mode:
authorKazu Hirata <kazu@google.com>2022-12-03 11:54:48 -0800
committerKazu Hirata <kazu@google.com>2022-12-03 11:54:48 -0800
commitcd8702efe7e6cacfd82cc4909e42718224bcd5d0 (patch)
tree9ffb6fae5c9aff022bdc76b195941a74a95dff40 /clang-tools-extra/clang-tidy/readability
parent5891420e6848e86a069dc6b7b73f175e22388f4a (diff)
downloadllvm-cd8702efe7e6cacfd82cc4909e42718224bcd5d0.zip
llvm-cd8702efe7e6cacfd82cc4909e42718224bcd5d0.tar.gz
llvm-cd8702efe7e6cacfd82cc4909e42718224bcd5d0.tar.bz2
[clang-tidy] 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
Diffstat (limited to 'clang-tools-extra/clang-tidy/readability')
-rw-r--r--clang-tools-extra/clang-tidy/readability/ConstReturnTypeCheck.cpp4
-rw-r--r--clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp12
-rw-r--r--clang-tools-extra/clang-tidy/readability/IsolateDeclarationCheck.cpp18
-rw-r--r--clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp2
-rw-r--r--clang-tools-extra/clang-tidy/readability/QualifiedAutoCheck.cpp8
-rw-r--r--clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.cpp2
-rw-r--r--clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp6
-rw-r--r--clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp2
-rw-r--r--clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp16
9 files changed, 35 insertions, 35 deletions
diff --git a/clang-tools-extra/clang-tidy/readability/ConstReturnTypeCheck.cpp b/clang-tools-extra/clang-tidy/readability/ConstReturnTypeCheck.cpp
index 7d8bee4..412d009 100644
--- a/clang-tools-extra/clang-tidy/readability/ConstReturnTypeCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ConstReturnTypeCheck.cpp
@@ -28,7 +28,7 @@ static llvm::Optional<Token>
findConstToRemove(const FunctionDecl *Def,
const MatchFinder::MatchResult &Result) {
if (!Def->getReturnType().isLocalConstQualified())
- return None;
+ return std::nullopt;
// Get the begin location for the function name, including any qualifiers
// written in the source (for out-of-line declarations). A FunctionDecl's
@@ -45,7 +45,7 @@ findConstToRemove(const FunctionDecl *Def,
*Result.SourceManager, Result.Context->getLangOpts());
if (FileRange.isInvalid())
- return None;
+ return std::nullopt;
return utils::lexer::getQualifyingToken(
tok::kw_const, FileRange, *Result.Context, *Result.SourceManager);
diff --git a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
index c038788..2cd40ed 100644
--- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -1361,14 +1361,14 @@ IdentifierNamingCheck::getFailureInfo(
const IdentifierNamingCheck::HungarianNotationOption &HNOption,
StyleKind SK, const SourceManager &SM, bool IgnoreFailedSplit) const {
if (SK == SK_Invalid || !NamingStyles[SK])
- return None;
+ return std::nullopt;
const IdentifierNamingCheck::NamingStyle &Style = *NamingStyles[SK];
if (Style.IgnoredRegexp.isValid() && Style.IgnoredRegexp.match(Name))
- return None;
+ return std::nullopt;
if (matchesStyle(Type, Name, Style, HNOption, ND))
- return None;
+ return std::nullopt;
std::string KindName =
fixupWithCase(Type, StyleNames[SK], ND, Style, HNOption,
@@ -1383,7 +1383,7 @@ IdentifierNamingCheck::getFailureInfo(
<< llvm::formatv(": unable to split words for {0} '{1}'\n",
KindName, Name));
}
- return None;
+ return std::nullopt;
}
return RenamerClangTidyCheck::FailureInfo{std::move(KindName),
std::move(Fixup)};
@@ -1395,7 +1395,7 @@ IdentifierNamingCheck::getDeclFailureInfo(const NamedDecl *Decl,
SourceLocation Loc = Decl->getLocation();
const FileStyle &FileStyle = getStyleForFile(SM.getFilename(Loc));
if (!FileStyle.isActive())
- return llvm::None;
+ return std::nullopt;
return getFailureInfo(HungarianNotation.getDeclTypeName(Decl),
Decl->getName(), Decl, Loc, FileStyle.getStyles(),
@@ -1411,7 +1411,7 @@ IdentifierNamingCheck::getMacroFailureInfo(const Token &MacroNameTok,
SourceLocation Loc = MacroNameTok.getLocation();
const FileStyle &Style = getStyleForFile(SM.getFilename(Loc));
if (!Style.isActive())
- return llvm::None;
+ return std::nullopt;
return getFailureInfo("", MacroNameTok.getIdentifierInfo()->getName(),
nullptr, Loc, Style.getStyles(), Style.getHNOption(),
diff --git a/clang-tools-extra/clang-tidy/readability/IsolateDeclarationCheck.cpp b/clang-tools-extra/clang-tidy/readability/IsolateDeclarationCheck.cpp
index 38e4272..45f3ea6 100644
--- a/clang-tools-extra/clang-tidy/readability/IsolateDeclarationCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/IsolateDeclarationCheck.cpp
@@ -110,10 +110,10 @@ declRanges(const DeclStmt *DS, const SourceManager &SM,
const LangOptions &LangOpts) {
std::size_t DeclCount = std::distance(DS->decl_begin(), DS->decl_end());
if (DeclCount < 2)
- return None;
+ return std::nullopt;
if (rangeContainsExpansionsOrDirectives(DS->getSourceRange(), SM, LangOpts))
- return None;
+ return std::nullopt;
// The initial type of the declaration and each declaration has it's own
// slice. This is necessary, because pointers and references bind only
@@ -127,12 +127,12 @@ declRanges(const DeclStmt *DS, const SourceManager &SM,
const auto *FirstDecl = dyn_cast<VarDecl>(*DS->decl_begin());
if (FirstDecl == nullptr)
- return None;
+ return std::nullopt;
// FIXME: Member pointers are not transformed correctly right now, that's
// why they are treated as problematic here.
if (typeIsMemberPointer(FirstDecl->getType().IgnoreParens().getTypePtr()))
- return None;
+ return std::nullopt;
// Consider the following case: 'int * pointer, value = 42;'
// Created slices (inclusive) [ ][ ] [ ]
@@ -168,7 +168,7 @@ declRanges(const DeclStmt *DS, const SourceManager &SM,
SourceRange DeclRange(DS->getBeginLoc(), Start);
if (DeclRange.isInvalid() || isMacroID(DeclRange))
- return None;
+ return std::nullopt;
// The first slice, that is prepended to every isolated declaration, is
// created.
@@ -182,7 +182,7 @@ declRanges(const DeclStmt *DS, const SourceManager &SM,
// FIXME: Member pointers are not transformed correctly right now, that's
// why they are treated as problematic here.
if (typeIsMemberPointer(CurrentDecl->getType().IgnoreParens().getTypePtr()))
- return None;
+ return std::nullopt;
SourceLocation DeclEnd =
CurrentDecl->hasInit()
@@ -192,7 +192,7 @@ declRanges(const DeclStmt *DS, const SourceManager &SM,
SourceRange VarNameRange(DeclBegin, DeclEnd);
if (VarNameRange.isInvalid() || isMacroID(VarNameRange))
- return None;
+ return std::nullopt;
Slices.emplace_back(VarNameRange);
DeclBegin = DeclEnd.getLocWithOffset(1);
@@ -212,14 +212,14 @@ collectSourceRanges(llvm::ArrayRef<SourceRange> Ranges, const SourceManager &SM,
LangOpts);
if (CharRange.isInvalid())
- return None;
+ return std::nullopt;
bool InvalidText = false;
StringRef Snippet =
Lexer::getSourceText(CharRange, SM, LangOpts, &InvalidText);
if (InvalidText)
- return None;
+ return std::nullopt;
Snippets.emplace_back(Snippet);
}
diff --git a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp
index 2de4ccd..7ee4838 100644
--- a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp
@@ -73,7 +73,7 @@ getNamespaceNameAsWritten(SourceLocation &Loc, const SourceManager &Sources,
} else if (T->is(tok::coloncolon)) {
Result.append("::");
} else { // Any other kind of token is unexpected here.
- return llvm::None;
+ return std::nullopt;
}
}
}
diff --git a/clang-tools-extra/clang-tidy/readability/QualifiedAutoCheck.cpp b/clang-tools-extra/clang-tidy/readability/QualifiedAutoCheck.cpp
index c564b5a..e25d147 100644
--- a/clang-tools-extra/clang-tidy/readability/QualifiedAutoCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/QualifiedAutoCheck.cpp
@@ -48,7 +48,7 @@ llvm::Optional<Token> findQualToken(const VarDecl *Decl, Qualifier Qual,
Result.Context->getLangOpts());
if (FileRange.isInvalid())
- return llvm::None;
+ return std::nullopt;
tok::TokenKind Tok =
Qual == Qualifier::Const
@@ -70,7 +70,7 @@ getTypeSpecifierLocation(const VarDecl *Var,
if (TypeSpecifier.getBegin().isMacroID() ||
TypeSpecifier.getEnd().isMacroID())
- return llvm::None;
+ return std::nullopt;
return TypeSpecifier;
}
@@ -78,11 +78,11 @@ llvm::Optional<SourceRange> mergeReplacementRange(SourceRange &TypeSpecifier,
const Token &ConstToken) {
if (TypeSpecifier.getBegin().getLocWithOffset(-1) == ConstToken.getEndLoc()) {
TypeSpecifier.setBegin(ConstToken.getLocation());
- return llvm::None;
+ return std::nullopt;
}
if (TypeSpecifier.getEnd().getLocWithOffset(1) == ConstToken.getLocation()) {
TypeSpecifier.setEnd(ConstToken.getEndLoc());
- return llvm::None;
+ return std::nullopt;
}
return SourceRange(ConstToken.getLocation(), ConstToken.getEndLoc());
}
diff --git a/clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.cpp b/clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.cpp
index a6e71e6..d1537eb 100644
--- a/clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.cpp
@@ -50,7 +50,7 @@ getConstructExprArgRange(const CXXConstructExpr &Construct) {
E = Arg->getEndLoc();
}
if (B.isInvalid() || E.isInvalid())
- return llvm::None;
+ return std::nullopt;
return SourceRange(B, E);
}
diff --git a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
index d78b5c5..1f1d605 100644
--- a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
@@ -300,18 +300,18 @@ public:
static Optional<bool> getAsBoolLiteral(const Expr *E, bool FilterMacro) {
if (const auto *Bool = dyn_cast<CXXBoolLiteralExpr>(E)) {
if (FilterMacro && Bool->getBeginLoc().isMacroID())
- return llvm::None;
+ return std::nullopt;
return Bool->getValue();
}
if (const auto *UnaryOp = dyn_cast<UnaryOperator>(E)) {
if (FilterMacro && UnaryOp->getBeginLoc().isMacroID())
- return None;
+ return std::nullopt;
if (UnaryOp->getOpcode() == UO_LNot)
if (Optional<bool> Res = getAsBoolLiteral(
UnaryOp->getSubExpr()->IgnoreImplicit(), FilterMacro))
return !*Res;
}
- return llvm::None;
+ return std::nullopt;
}
template <typename Node> struct NodeAndBool {
diff --git a/clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp b/clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp
index 4841da5..2a5e614 100644
--- a/clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp
@@ -587,7 +587,7 @@ Optional<int8_t> SuspiciousCallArgumentCheck::getBound(Heuristic H,
assert(Idx < HeuristicCount);
if (!Defaults[Idx].hasBounds())
- return None;
+ return std::nullopt;
switch (BK) {
case BoundKind::DissimilarBelow:
diff --git a/clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp b/clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp
index 0b1f3dd..ee760f7 100644
--- a/clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp
@@ -67,11 +67,11 @@ llvm::Optional<SourceLocation> getMacroAwareLocation(SourceLocation Loc,
const SourceManager &SM) {
// Do nothing if the provided location is invalid.
if (Loc.isInvalid())
- return llvm::None;
+ return std::nullopt;
// Look where the location was *actually* written.
SourceLocation SpellingLoc = SM.getSpellingLoc(Loc);
if (SpellingLoc.isInvalid())
- return llvm::None;
+ return std::nullopt;
return SpellingLoc;
}
@@ -81,7 +81,7 @@ llvm::Optional<SourceRange> getMacroAwareSourceRange(SourceRange Loc,
getMacroAwareLocation(Loc.getBegin(), SM);
llvm::Optional<SourceLocation> End = getMacroAwareLocation(Loc.getEnd(), SM);
if (!Begin || !End)
- return llvm::None;
+ return std::nullopt;
return SourceRange(*Begin, *End);
}
@@ -100,7 +100,7 @@ getNewSuffix(llvm::StringRef OldSuffix,
if (NewSuffix != NewSuffixes.end())
return NewSuffix->str();
// Nope, I guess we have to keep it as-is.
- return llvm::None;
+ return std::nullopt;
}
template <typename LiteralType>
@@ -123,7 +123,7 @@ shouldReplaceLiteralSuffix(const Expr &Literal,
llvm::Optional<SourceRange> Range =
getMacroAwareSourceRange(ReplacementDsc.LiteralLocation, SM);
if (!Range)
- return llvm::None;
+ return std::nullopt;
if (RangeCanBeFixed)
ReplacementDsc.LiteralLocation = *Range;
@@ -138,7 +138,7 @@ shouldReplaceLiteralSuffix(const Expr &Literal,
// Make sure the first character is actually a digit, instead of
// something else, like a non-type template parameter.
if (!std::isdigit(static_cast<unsigned char>(LiteralSourceText.front())))
- return llvm::None;
+ return std::nullopt;
size_t Skip = 0;
@@ -161,7 +161,7 @@ shouldReplaceLiteralSuffix(const Expr &Literal,
// We can't check whether the *Literal has any suffix or not without actually
// looking for the suffix. So it is totally possible that there is no suffix.
if (Skip == StringRef::npos)
- return llvm::None;
+ return std::nullopt;
// Move the cursor in the source range to the beginning of the suffix.
Range->setBegin(Range->getBegin().getLocWithOffset(Skip));
@@ -174,7 +174,7 @@ shouldReplaceLiteralSuffix(const Expr &Literal,
llvm::Optional<std::string> NewSuffix =
getNewSuffix(ReplacementDsc.OldSuffix, NewSuffixes);
if (!NewSuffix || ReplacementDsc.OldSuffix == *NewSuffix)
- return llvm::None; // The suffix was already the way it should be.
+ return std::nullopt; // The suffix was already the way it should be.
if (RangeCanBeFixed)
ReplacementDsc.FixIt = FixItHint::CreateReplacement(*Range, *NewSuffix);