Skip to content

[clang-tidy] refactor misc-header-include-cycle #94697

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

HerrCai0907
Copy link
Contributor

  1. merge valid check
  2. use range base loop

1. merge valid check
2. use range base loop
@llvmbot
Copy link
Member

llvmbot commented Jun 6, 2024

@llvm/pr-subscribers-clang-tidy

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

Author: Congcong Cai (HerrCai0907)

Changes
  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 --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 {

@HerrCai0907 HerrCai0907 requested a review from PiotrZSL June 6, 2024 23:27
@HerrCai0907 HerrCai0907 merged commit c5ff983 into llvm:main Jun 7, 2024
8 of 9 checks passed
@HerrCai0907 HerrCai0907 deleted the refactor/misc-header-include-cycle branch June 7, 2024 05:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants