[clang-tools-extra] [clang-tidy] refactor misc-header-include-cycle (PR #94697)

via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 6 16:08:27 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-tools-extra

Author: Congcong Cai (HerrCai0907)

<details>
<summary>Changes</summary>

1. merge valid check
2. use range base loop


---
Full diff: https://github.com/llvm/llvm-project/pull/94697.diff


1 Files Affected:

- (modified) clang-tools-extra/clang-tidy/misc/HeaderIncludeCycleCheck.cpp (+4-9) 


``````````diff
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 {

``````````

</details>


https://github.com/llvm/llvm-project/pull/94697


More information about the cfe-commits mailing list