[clang-tools-extra] [clang-tidy] refactor misc-header-include-cycle (PR #94697)
Congcong Cai via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 6 16:07:58 PDT 2024
https://github.com/HerrCai0907 created https://github.com/llvm/llvm-project/pull/94697
1. merge valid check
2. use range base loop
>From 8104085685772f93bcc595858821f839636ada9e Mon Sep 17 00:00:00 2001
From: Congcong Cai <congcongcai0907 at 163.com>
Date: Fri, 7 Jun 2024 07:06:37 +0800
Subject: [PATCH] [clang-tidy] refactor misc-header-include-cycle
1. merge valid check
2. use range base loop
---
.../clang-tidy/misc/HeaderIncludeCycleCheck.cpp | 13 ++++---------
1 file changed, 4 insertions(+), 9 deletions(-)
diff --git a/clang-tools-extra/clang-tidy/misc/HeaderIncludeCycleCheck.cpp b/clang-tools-extra/clang-tidy/misc/HeaderIncludeCycleCheck.cpp
index 37bc577c646ab..cdb5e6b16069b 100644
--- a/clang-tools-extra/clang-tidy/misc/HeaderIncludeCycleCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/HeaderIncludeCycleCheck.cpp
@@ -130,20 +130,15 @@ class CyclicDependencyCallbacks : public PPCallbacks {
<< FileName;
const bool IsIncludePathValid =
- std::all_of(Files.rbegin(), It, [](const Include &Elem) {
+ std::all_of(Files.rbegin(), It + 1, [](const Include &Elem) {
return !Elem.Name.empty() && Elem.Loc.isValid();
});
-
if (!IsIncludePathValid)
return;
- auto CurrentIt = Files.rbegin();
- do {
- if (CurrentIt->Loc.isValid())
- Check.diag(CurrentIt->Loc, "'%0' included from here",
- DiagnosticIDs::Note)
- << CurrentIt->Name;
- } while (CurrentIt++ != It);
+ for (const Include &I : llvm::make_range(Files.rbegin(), It + 1))
+ Check.diag(I.Loc, "'%0' included from here", DiagnosticIDs::Note)
+ << I.Name;
}
bool isFileIgnored(StringRef FileName) const {
More information about the cfe-commits
mailing list