Skip to content

Commit bb85bac

Browse files
committed
[clang-tidy][NFC] Enable readability-any-all-of check
1 parent 577b519 commit bb85bac

25 files changed

+99
-164
lines changed

clang-tools-extra/clang-tidy/.clang-tidy

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ Checks: >
3030
-readability-qualified-auto,
3131
-readability-simplify-boolean-expr,
3232
-readability-static-definition-in-anonymous-namespace,
33-
-readability-suspicious-call-argument,
34-
-readability-use-anyofallof
33+
-readability-suspicious-call-argument
3534
3635
CheckOptions:
3736
- key: performance-move-const-arg.CheckTriviallyCopyableMove

clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -478,11 +478,10 @@ bool ClangTidyDiagnosticConsumer::passesLineFilter(StringRef FileName,
478478
if (FileName.ends_with(Filter.Name)) {
479479
if (Filter.LineRanges.empty())
480480
return true;
481-
for (const FileFilter::LineRange &Range : Filter.LineRanges) {
482-
if (Range.first <= LineNumber && LineNumber <= Range.second)
483-
return true;
484-
}
485-
return false;
481+
return llvm::any_of(
482+
Filter.LineRanges, [&](const FileFilter::LineRange &Range) {
483+
return Range.first <= LineNumber && LineNumber <= Range.second;
484+
});
486485
}
487486
}
488487
return false;

clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,9 @@ static bool isFallthroughSwitchBranch(const SwitchBranch &Branch) {
7575
if (!S)
7676
return true;
7777

78-
for (const Attr *A : S->getAttrs()) {
79-
if (isa<FallThroughAttr>(A))
80-
return false;
81-
}
82-
83-
return true;
78+
return llvm::all_of(S->getAttrs(), [](const Attr *A) {
79+
return !isa<FallThroughAttr>(A);
80+
});
8481
}
8582
} Visitor;
8683

clang-tools-extra/clang-tidy/bugprone/CapturingThisInMemberVariableCheck.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,15 @@ AST_MATCHER(CXXRecordDecl, correctHandleCaptureThisLambda) {
4848
if (C->isCopyOrMoveConstructor() && C->isDefaulted() && !C->isDeleted())
4949
return false;
5050
}
51-
for (const CXXMethodDecl *M : Node.methods()) {
52-
if (M->isCopyAssignmentOperator())
53-
llvm::errs() << M->isDeleted() << "\n";
54-
if (M->isCopyAssignmentOperator() && M->isDefaulted() && !M->isDeleted())
55-
return false;
56-
if (M->isMoveAssignmentOperator() && M->isDefaulted() && !M->isDeleted())
57-
return false;
58-
}
51+
if (llvm::any_of(Node.methods(), [](const CXXMethodDecl *M) {
52+
if (M->isCopyAssignmentOperator())
53+
llvm::errs() << M->isDeleted() << "\n";
54+
return (M->isCopyAssignmentOperator() && M->isDefaulted() &&
55+
!M->isDeleted()) ||
56+
(M->isMoveAssignmentOperator() && M->isDefaulted() &&
57+
!M->isDeleted());
58+
}))
59+
return false;
5960
// FIXME: find ways to identifier correct handle capture this lambda
6061
return true;
6162
}

clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1589,11 +1589,9 @@ static bool lazyMapOfSetsIntersectionExists(const MapTy &Map, const ElemTy &E1,
15891589
if (E1Iterator == Map.end() || E2Iterator == Map.end())
15901590
return false;
15911591

1592-
for (const auto &E1SetElem : E1Iterator->second)
1593-
if (E2Iterator->second.contains(E1SetElem))
1594-
return true;
1595-
1596-
return false;
1592+
return llvm::any_of(E1Iterator->second, [&](const auto &E1SetElem) {
1593+
return E2Iterator->second.contains(E1SetElem);
1594+
});
15971595
}
15981596

15991597
/// Implements the heuristic that marks two parameters related if there is

clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,9 @@ static bool isAtLeastOneCondVarChanged(const Decl *Func, const Stmt *LoopStmt,
119119
if (isVarThatIsPossiblyChanged(Func, LoopStmt, Cond, Context))
120120
return true;
121121

122-
for (const Stmt *Child : Cond->children()) {
123-
if (!Child)
124-
continue;
125-
126-
if (isAtLeastOneCondVarChanged(Func, LoopStmt, Child, Context))
127-
return true;
128-
}
129-
return false;
122+
return llvm::any_of(Cond->children(), [&](const Stmt *Child) {
123+
return Child && isAtLeastOneCondVarChanged(Func, LoopStmt, Child, Context);
124+
});
130125
}
131126

132127
/// Return the variable names in `Cond`.
@@ -240,10 +235,9 @@ static bool hasStaticLocalVariable(const Stmt *Cond) {
240235
return true;
241236
}
242237

243-
for (const Stmt *Child : Cond->children())
244-
if (Child && hasStaticLocalVariable(Child))
245-
return true;
246-
return false;
238+
return llvm::any_of(Cond->children(), [](const Stmt *Child) {
239+
return Child && hasStaticLocalVariable(Child);
240+
});
247241
}
248242

249243
/// Tests if the loop condition `Cond` involves static local variables and

clang-tools-extra/clang-tidy/bugprone/SuspiciousReallocUsageCheck.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,9 @@ class FindAssignToVarBefore
9292
return false;
9393
}
9494
bool VisitStmt(const Stmt *S) {
95-
for (const Stmt *Child : S->children())
96-
if (Child && Visit(Child))
97-
return true;
98-
return false;
95+
return llvm::any_of(S->children(), [this](const Stmt *Child) {
96+
return Child && Visit(Child);
97+
});
9998
}
10099
};
101100

clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ namespace clang::tidy::cppcoreguidelines {
1919
namespace {
2020
AST_MATCHER_P(CXXForRangeStmt, hasRangeBeginEndStmt,
2121
ast_matchers::internal::Matcher<DeclStmt>, InnerMatcher) {
22-
for (const DeclStmt *Stmt : {Node.getBeginStmt(), Node.getEndStmt()})
23-
if (Stmt != nullptr && InnerMatcher.matches(*Stmt, Finder, Builder))
24-
return true;
25-
return false;
22+
const DeclStmt *Stmts[] = {Node.getBeginStmt(), Node.getEndStmt()};
23+
return llvm::any_of(Stmts, [&](const DeclStmt *Stmt) {
24+
return Stmt != nullptr && InnerMatcher.matches(*Stmt, Finder, Builder);
25+
});
2626
}
2727

2828
AST_MATCHER(Stmt, isInsideOfRangeBeginEndStmt) {

clang-tools-extra/clang-tidy/fuchsia/VirtualInheritanceCheck.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@ AST_MATCHER(CXXRecordDecl, hasDirectVirtualBaseClass) {
2020
return false;
2121
if (!Node.getNumVBases())
2222
return false;
23-
for (const CXXBaseSpecifier &Base : Node.bases())
24-
if (Base.isVirtual())
25-
return true;
26-
return false;
23+
return llvm::any_of(Node.bases(), [](const CXXBaseSpecifier &Base) {
24+
return Base.isVirtual();
25+
});
2726
}
2827
} // namespace
2928

clang-tools-extra/clang-tidy/misc/NewDeleteOverloadsCheck.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,17 +114,15 @@ hasCorrespondingOverloadInBaseClass(const CXXMethodDecl *MD,
114114
RD = MD->getParent();
115115
}
116116

117-
for (const auto &BS : RD->bases()) {
117+
return llvm::any_of(RD->bases(), [&](const auto &BS) {
118118
// We can't say much about a dependent base class, but to avoid false
119119
// positives assume it can have a corresponding overload.
120120
if (BS.getType()->isDependentType())
121121
return true;
122122
if (const auto *BaseRD = BS.getType()->getAsCXXRecordDecl())
123-
if (hasCorrespondingOverloadInBaseClass(MD, BaseRD))
124-
return true;
125-
}
126-
127-
return false;
123+
return hasCorrespondingOverloadInBaseClass(MD, BaseRD);
124+
return false;
125+
});
128126
}
129127

130128
void NewDeleteOverloadsCheck::registerMatchers(MatchFinder *Finder) {

0 commit comments

Comments
 (0)