Skip to content
Open
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
3 changes: 1 addition & 2 deletions clang-tools-extra/clang-tidy/.clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ Checks: >
-readability-qualified-auto,
-readability-simplify-boolean-expr,
-readability-static-definition-in-anonymous-namespace,
-readability-suspicious-call-argument,
-readability-use-anyofallof
-readability-suspicious-call-argument

CheckOptions:
- key: performance-move-const-arg.CheckTriviallyCopyableMove
Expand Down
9 changes: 4 additions & 5 deletions clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,11 +478,10 @@ bool ClangTidyDiagnosticConsumer::passesLineFilter(StringRef FileName,
if (FileName.ends_with(Filter.Name)) {
if (Filter.LineRanges.empty())
return true;
for (const FileFilter::LineRange &Range : Filter.LineRanges) {
if (Range.first <= LineNumber && LineNumber <= Range.second)
return true;
}
return false;
return llvm::any_of(
Filter.LineRanges, [&](const FileFilter::LineRange &Range) {
return Range.first <= LineNumber && LineNumber <= Range.second;
});
}
}
return false;
Expand Down
9 changes: 3 additions & 6 deletions clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,9 @@ static bool isFallthroughSwitchBranch(const SwitchBranch &Branch) {
if (!S)
return true;

for (const Attr *A : S->getAttrs()) {
if (isa<FallThroughAttr>(A))
return false;
}

return true;
return llvm::all_of(S->getAttrs(), [](const Attr *A) {
return !isa<FallThroughAttr>(A);
});
}
} Visitor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,17 @@ AST_MATCHER(CXXRecordDecl, correctHandleCaptureThisLambda) {
if (Node.hasSimpleMoveAssignment())
return false;

for (const CXXConstructorDecl *C : Node.ctors()) {
if (C->isCopyOrMoveConstructor() && C->isDefaulted() && !C->isDeleted())
return false;
}
for (const CXXMethodDecl *M : Node.methods()) {
if (M->isCopyAssignmentOperator())
llvm::errs() << M->isDeleted() << "\n";
if (M->isCopyAssignmentOperator() && M->isDefaulted() && !M->isDeleted())
return false;
if (M->isMoveAssignmentOperator() && M->isDefaulted() && !M->isDeleted())
return false;
}
if (llvm::any_of(Node.ctors(), [](const CXXConstructorDecl *C) {
return C->isCopyOrMoveConstructor() && C->isDefaulted() &&
!C->isDeleted();
}))
return false;
if (llvm::any_of(Node.methods(), [](const CXXMethodDecl *M) {
return (M->isCopyAssignmentOperator() ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

llvm::errs() << M->isDeleted() << "\n"; disappeared. Were tests affected?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No affected tests, I believe this is a debug artifact: I've seen such errs() before in reviews, and we removed them. @HerrCai0907, could you confirm this?

M->isMoveAssignmentOperator()) &&
M->isDefaulted() && !M->isDeleted();
}))
return false;
// FIXME: find ways to identifier correct handle capture this lambda
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1589,11 +1589,9 @@ static bool lazyMapOfSetsIntersectionExists(const MapTy &Map, const ElemTy &E1,
if (E1Iterator == Map.end() || E2Iterator == Map.end())
return false;

for (const auto &E1SetElem : E1Iterator->second)
if (E2Iterator->second.contains(E1SetElem))
return true;

return false;
return llvm::any_of(E1Iterator->second, [&E2Iterator](const auto &E1SetElem) {
return E2Iterator->second.contains(E1SetElem);
});
}

/// Implements the heuristic that marks two parameters related if there is
Expand Down
18 changes: 6 additions & 12 deletions clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,9 @@ static bool isAtLeastOneCondVarChanged(const Decl *Func, const Stmt *LoopStmt,
if (isVarThatIsPossiblyChanged(Func, LoopStmt, Cond, Context))
return true;

for (const Stmt *Child : Cond->children()) {
if (!Child)
continue;

if (isAtLeastOneCondVarChanged(Func, LoopStmt, Child, Context))
return true;
}
return false;
return llvm::any_of(Cond->children(), [&](const Stmt *Child) {
return Child && isAtLeastOneCondVarChanged(Func, LoopStmt, Child, Context);
});
}

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

for (const Stmt *Child : Cond->children())
if (Child && hasStaticLocalVariable(Child))
return true;
return false;
return llvm::any_of(Cond->children(), [](const Stmt *Child) {
return Child && hasStaticLocalVariable(Child);
});
}

/// Tests if the loop condition `Cond` involves static local variables and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,9 @@ class FindAssignToVarBefore
return false;
}
bool VisitStmt(const Stmt *S) {
for (const Stmt *Child : S->children())
if (Child && Visit(Child))
return true;
return false;
return llvm::any_of(S->children(), [this](const Stmt *Child) {
return Child && Visit(Child);
});
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ namespace clang::tidy::cppcoreguidelines {
namespace {
AST_MATCHER_P(CXXForRangeStmt, hasRangeBeginEndStmt,
ast_matchers::internal::Matcher<DeclStmt>, InnerMatcher) {
for (const DeclStmt *Stmt : {Node.getBeginStmt(), Node.getEndStmt()})
if (Stmt != nullptr && InnerMatcher.matches(*Stmt, Finder, Builder))
return true;
return false;
return llvm::any_of(llvm::ArrayRef{Node.getBeginStmt(), Node.getEndStmt()},
[&](const DeclStmt *Stmt) {
return Stmt &&
InnerMatcher.matches(*Stmt, Finder, Builder);
});
}

AST_MATCHER(Stmt, isInsideOfRangeBeginEndStmt) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ AST_MATCHER(CXXRecordDecl, hasDirectVirtualBaseClass) {
return false;
if (!Node.getNumVBases())
return false;
for (const CXXBaseSpecifier &Base : Node.bases())
if (Base.isVirtual())
return true;
return false;
return llvm::any_of(Node.bases(), [](const CXXBaseSpecifier &Base) {
return Base.isVirtual();
});
}
} // namespace

Expand Down
12 changes: 5 additions & 7 deletions clang-tools-extra/clang-tidy/misc/NewDeleteOverloadsCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,15 @@ hasCorrespondingOverloadInBaseClass(const CXXMethodDecl *MD,
RD = MD->getParent();
}

for (const auto &BS : RD->bases()) {
return llvm::any_of(RD->bases(), [&](const CXXBaseSpecifier &BS) {
// We can't say much about a dependent base class, but to avoid false
// positives assume it can have a corresponding overload.
if (BS.getType()->isDependentType())
return true;
if (const auto *BaseRD = BS.getType()->getAsCXXRecordDecl())
if (hasCorrespondingOverloadInBaseClass(MD, BaseRD))
return true;
}

return false;
if (const CXXRecordDecl *BaseRD = BS.getType()->getAsCXXRecordDecl())
return hasCorrespondingOverloadInBaseClass(MD, BaseRD);
return false;
});
}

void NewDeleteOverloadsCheck::registerMatchers(MatchFinder *Finder) {
Expand Down
11 changes: 4 additions & 7 deletions clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,10 @@ static bool isOverrideMethod(const FunctionDecl *Function) {

static bool hasAttrAfterParam(const SourceManager *SourceManager,
const ParmVarDecl *Param) {
for (const auto *Attr : Param->attrs()) {
if (SourceManager->isBeforeInTranslationUnit(Param->getLocation(),
Attr->getLocation())) {
return true;
}
}
return false;
return llvm::any_of(Param->attrs(), [&](const Attr *Attr) {
return SourceManager->isBeforeInTranslationUnit(Param->getLocation(),
Attr->getLocation());
});
}

void UnusedParametersCheck::registerMatchers(MatchFinder *Finder) {
Expand Down
19 changes: 8 additions & 11 deletions clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,27 +511,24 @@ static bool canBeModified(ASTContext *Context, const Expr *E) {
/// Returns true when it can be guaranteed that the elements of the
/// container are not being modified.
static bool usagesAreConst(ASTContext *Context, const UsageResult &Usages) {
for (const Usage &U : Usages) {
return llvm::none_of(Usages, [&Context](const Usage &U) {
// Lambda captures are just redeclarations (VarDecl) of the same variable,
// not expressions. If we want to know if a variable that is captured by
// reference can be modified in an usage inside the lambda's body, we need
// to find the expression corresponding to that particular usage, later in
// this loop.
if (U.Kind != Usage::UK_CaptureByCopy && U.Kind != Usage::UK_CaptureByRef &&
canBeModified(Context, U.Expression))
return false;
}
return true;
return U.Kind != Usage::UK_CaptureByCopy &&
U.Kind != Usage::UK_CaptureByRef &&
canBeModified(Context, U.Expression);
});
}

/// Returns true if the elements of the container are never accessed
/// by reference.
static bool usagesReturnRValues(const UsageResult &Usages) {
for (const auto &U : Usages) {
if (U.Expression && !U.Expression->isPRValue())
return false;
}
return true;
return llvm::all_of(Usages, [](const Usage &U) {
return !U.Expression || U.Expression->isPRValue();
});
}

/// Returns true if the container is const-qualified.
Expand Down
19 changes: 7 additions & 12 deletions clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,11 @@ bool DependencyFinderASTVisitor::VisitVarDecl(VarDecl *V) {

// Next, check if the variable was removed from existence by an earlier
// iteration.
for (const auto &I : *ReplacedVars) {
if (I.second == V) {
DependsOnInsideVariable = true;
return false;
}
}
return true;
if (llvm::none_of(*ReplacedVars,
[&](const auto &I) { return I.second == V; }))
return true;
DependsOnInsideVariable = true;
return false;
}

/// If we already created a variable for TheLoop, check to make sure
Expand Down Expand Up @@ -234,11 +232,8 @@ static bool containsExpr(ASTContext *Context, const ContainerT *Container,
const Expr *E) {
llvm::FoldingSetNodeID ID;
E->Profile(ID, *Context, true);
for (const auto &I : *Container) {
if (ID == I.second)
return true;
}
return false;
return llvm::any_of(*Container,
[&](const auto &I) { return ID == I.second; });
}

/// Returns true when the index expression is a declaration reference to
Expand Down
6 changes: 1 addition & 5 deletions clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,7 @@ static bool hasRValueOverload(const CXXConstructorDecl *Ctor,
return true;
};

for (const auto *Candidate : Record->ctors()) {
if (IsRValueOverload(Candidate))
return true;
}
return false;
return llvm::any_of(Record->ctors(), IsRValueOverload);
}

/// Find all references to \p ParamDecl across all of the
Expand Down
17 changes: 6 additions & 11 deletions clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,12 @@ AST_MATCHER_P(NamedDecl, hasAnyNameIgnoringTemplates, std::vector<StringRef>,
// clang/lib/ASTMatchers/ASTMatchersInternal.cpp and checks whether
// FullNameTrimmed matches any of the given Names.
const StringRef FullNameTrimmedRef = FullNameTrimmed;
for (const StringRef Pattern : Names) {
if (Pattern.starts_with("::")) {
if (FullNameTrimmed == Pattern)
return true;
} else if (FullNameTrimmedRef.ends_with(Pattern) &&
FullNameTrimmedRef.drop_back(Pattern.size()).ends_with("::")) {
return true;
}
}

return false;
return llvm::any_of(Names, [&](const StringRef Pattern) {
if (Pattern.starts_with("::"))
return FullNameTrimmed == Pattern;
return FullNameTrimmedRef.ends_with(Pattern) &&
FullNameTrimmedRef.drop_back(Pattern.size()).ends_with("::");
});
}

// Checks if the given matcher is the last argument of the given CallExpr.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,12 @@ struct UnqualNameVisitor : public RecursiveASTVisitor<UnqualNameVisitor> {

bool visitUnqualName(StringRef UnqualName) {
// Check for collisions with function arguments.
for (const ParmVarDecl *Param : F.parameters())
Collision = llvm::any_of(F.parameters(), [&](ParmVarDecl *Param) {
if (const IdentifierInfo *Ident = Param->getIdentifier())
if (Ident->getName() == UnqualName) {
Collision = true;
return true;
}
return false;
return Ident->getName() == UnqualName;
return false;
});
return Collision;
}

bool TraverseTypeLoc(TypeLoc TL, bool TraverseQualifier = true) {
Expand Down
8 changes: 3 additions & 5 deletions clang-tools-extra/clang-tidy/objc/MissingHashCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@ AST_MATCHER_P(ObjCImplementationDecl, hasInterface,
AST_MATCHER_P(ObjCContainerDecl, hasInstanceMethod,
ast_matchers::internal::Matcher<ObjCMethodDecl>, Base) {
// Check each instance method against the provided matcher.
for (const auto *I : Node.instance_methods()) {
if (Base.matches(*I, Finder, Builder))
return true;
}
return false;
return llvm::any_of(Node.instance_methods(), [&](const ObjCMethodDecl *I) {
return Base.matches(*I, Finder, Builder);
});
}

} // namespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,9 @@ namespace {
AST_MATCHER(Decl, isFirstDecl) { return Node.isFirstDecl(); }

AST_MATCHER_P(CXXRecordDecl, hasBase, Matcher<QualType>, InnerMatcher) {
for (const CXXBaseSpecifier &BaseSpec : Node.bases()) {
const QualType BaseType = BaseSpec.getType();
if (InnerMatcher.matches(BaseType, Finder, Builder))
return true;
}
return false;
return llvm::any_of(Node.bases(), [&](const CXXBaseSpecifier &BaseSpec) {
return InnerMatcher.matches(BaseSpec.getType(), Finder, Builder);
});
}

} // namespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,9 @@ namespace clang::tidy::readability {
namespace {

AST_MATCHER(CXXMethodDecl, hasOnlyDefaultParameters) {
for (const auto *Param : Node.parameters()) {
if (!Param->hasDefaultArg())
return false;
}

return true;
return llvm::all_of(Node.parameters(), [](const ParmVarDecl *Param) {
return Param->hasDefaultArg();
});
}

const auto DefaultSmartPointers = "::std::shared_ptr;::std::unique_ptr;"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,9 @@ getRepresentation(const std::vector<llvm::StringRef> &Config,
template <typename T>
static bool isAnyOperatorEnabled(const std::vector<llvm::StringRef> &Config,
const T &Operators) {
for (const auto &[traditional, alternative] : Operators) {
if (!getRepresentation(Config, traditional, alternative).empty())
return true;
}
return false;
return llvm::any_of(Operators, [&](const auto &Op) {
return !getRepresentation(Config, Op.first, Op.second).empty();
});
}

OperatorsRepresentationCheck::OperatorsRepresentationCheck(
Expand Down
Loading
Loading