[clang] [clang-tools-extra] [clang-tidy] Add experimental header-filter scope (PR #194370)

via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 27 06:40:15 PDT 2026


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp,h -- clang-tools-extra/clang-tidy/HeaderFilterHelpers.h clang-tools-extra/test/clang-tidy/infrastructure/Inputs/experimental-header-filter-scope/confusable_header.h clang-tools-extra/test/clang-tidy/infrastructure/experimental-header-filter-scope.cpp clang-tools-extra/clang-tidy/ClangTidy.cpp clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h clang-tools-extra/clang-tidy/ClangTidyOptions.cpp clang-tools-extra/clang-tidy/ClangTidyOptions.h clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp clang-tools-extra/test/clang-tidy/infrastructure/diagnostic.cpp clang-tools-extra/test/clang-tidy/infrastructure/dump-config-filtering.cpp clang-tools-extra/test/clang-tidy/infrastructure/run-clang-tidy.cpp clang/include/clang/ASTMatchers/ASTMatchFinder.h clang/lib/ASTMatchers/ASTMatchFinder.cpp clang/unittests/ASTMatchers/ASTMatchersInternalTest.cpp --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/clang-tools-extra/clang-tidy/ClangTidy.cpp b/clang-tools-extra/clang-tidy/ClangTidy.cpp
index 3292dc44b..e2a9d4160 100644
--- a/clang-tools-extra/clang-tidy/ClangTidy.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidy.cpp
@@ -453,10 +453,10 @@ ClangTidyASTConsumerFactory::createASTConsumer(CompilerInstance &Compiler,
     auto LocationFilter = std::make_shared<HeaderFilterLocationFilter>(
         Context.getOptions().HeaderFilterRegex.value_or(""),
         Context.getOptions().ExcludeHeaderFilterRegex.value_or(""));
-    FinderOptions.ShouldSkipLocation =
-        [LocationFilter, SM](SourceLocation Location) {
-          return !LocationFilter->shouldInclude(Location, *SM);
-        };
+    FinderOptions.ShouldSkipLocation = [LocationFilter,
+                                        SM](SourceLocation Location) {
+      return !LocationFilter->shouldInclude(Location, *SM);
+    };
   }
 
   auto Finder =
diff --git a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
index 6b3569f7c..d35cd954e 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -580,9 +580,9 @@ void ClangTidyDiagnosticConsumer::checkFilters(SourceLocation Location,
       (Sources.isInSystemHeader(Location) || Sources.isInSystemMacro(Location)))
     return;
 
-  LastErrorRelatesToUserCode = LastErrorRelatesToUserCode ||
-                               getHeaderFilterLocationFilter().shouldInclude(
-                                   Location, Sources);
+  LastErrorRelatesToUserCode =
+      LastErrorRelatesToUserCode ||
+      getHeaderFilterLocationFilter().shouldInclude(Location, Sources);
 
   // FIXME: We start with a conservative approach here, but the actual type of
   // location needed depends on the check (in particular, where this check wants
diff --git a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
index 5ed56e30c..e5757528e 100644
--- a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
+++ b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
@@ -163,8 +163,7 @@ option in .clang-tidy file, if any.
                                                 cl::cat(ClangTidyCategory));
 
 static cl::opt<bool>
-    ExperimentalHeaderFilterScope("experimental-header-filter-scope",
-                                  desc(R"(
+    ExperimentalHeaderFilterScope("experimental-header-filter-scope", desc(R"(
 When enabled, clang-tidy experimentally skips
 AST matching for declarations in headers that
 do not match -header-filter or that match
@@ -177,8 +176,7 @@ This option overrides the
 'ExperimentalHeaderFilterScope' option in
 .clang-tidy file, if any.
 )"),
-                                  cl::init(false),
-                                  cl::cat(ClangTidyCategory));
+                                  cl::init(false), cl::cat(ClangTidyCategory));
 
 static cl::opt<bool> SystemHeaders("system-headers", desc(R"(
 Display the errors from system headers.
diff --git a/clang/unittests/ASTMatchers/ASTMatchersInternalTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersInternalTest.cpp
index 9e1330200..1fc184fd6 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersInternalTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersInternalTest.cpp
@@ -351,8 +351,8 @@ TEST(MatchFinder, HonorsShouldSkipLocation) {
   auto AST = tooling::buildASTFromCodeWithArgs(
       "#include \"other.h\"\n"
       "class MainDecl {};\n",
-      {"-std=gnu++11", "-target", "i386-unknown-unknown", "-I/"},
-      "input.cc", "clang-tool", std::make_shared<PCHContainerOperations>(),
+      {"-std=gnu++11", "-target", "i386-unknown-unknown", "-I/"}, "input.cc",
+      "clang-tool", std::make_shared<PCHContainerOperations>(),
       tooling::getClangStripDependencyFileAdjuster(), M);
   ASSERT_TRUE(AST);
 
@@ -372,9 +372,9 @@ TEST(MatchFinder, HonorsShouldSkipLocation) {
     std::vector<std::string> Names;
     RecordCallback Callback(Names);
     MatchFinder Finder(std::move(Options));
-    Finder.addMatcher(cxxRecordDecl(isDefinition(), unless(isImplicit()))
-                          .bind("record"),
-                      &Callback);
+    Finder.addMatcher(
+        cxxRecordDecl(isDefinition(), unless(isImplicit())).bind("record"),
+        &Callback);
     Finder.matchAST(AST->getASTContext());
     llvm::sort(Names);
     return Names;

``````````

</details>


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


More information about the cfe-commits mailing list