[clang-tools-extra] [clang-tidy] Run analysis even with no checks (as long as `--allow-no-checks` is passed) (PR #194006)

Victor Chernyakin via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 24 09:31:13 PDT 2026


https://github.com/localspook created https://github.com/llvm/llvm-project/pull/194006

None

>From 52f082804dd66996bc4bf0345f67e09d77e90246 Mon Sep 17 00:00:00 2001
From: Victor Chernyakin <chernyakin.victor.j at outlook.com>
Date: Fri, 24 Apr 2026 08:39:09 -0700
Subject: [PATCH] [clang-tidy] Run analysis even with no checks (as long as
 `--allow-no-checks` is passed)

---
 clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp         | 6 +-----
 .../test/clang-tidy/infrastructure/allow-no-checks.cpp      | 4 +---
 .../header-filter-from-config-file/inheritance/foo.cpp      | 2 +-
 .../header-filter-from-config-file/simple/foo.cpp           | 2 +-
 .../test/clang-tidy/infrastructure/nolintbeginend-LIFO.cpp  | 2 +-
 .../infrastructure/nolintbeginend-begin-all-end-glob.cpp    | 2 +-
 .../nolintbeginend-begin-all-end-specific.cpp               | 2 +-
 .../infrastructure/nolintbeginend-begin-at-eof.cpp          | 2 +-
 .../infrastructure/nolintbeginend-begin-glob-end-all.cpp    | 2 +-
 .../nolintbeginend-begin-glob-end-specific.cpp              | 2 +-
 .../nolintbeginend-begin-multiple-end-single.cpp            | 2 +-
 .../nolintbeginend-begin-single-end-multiple.cpp            | 2 +-
 .../nolintbeginend-begin-specific-end-all.cpp               | 2 +-
 .../nolintbeginend-begin-specific-end-glob.cpp              | 2 +-
 .../infrastructure/nolintbeginend-begin-without-end.cpp     | 2 +-
 .../clang-tidy/infrastructure/nolintbeginend-end-at-sof.cpp | 2 +-
 .../infrastructure/nolintbeginend-end-without-begin.cpp     | 2 +-
 .../nolintbeginend-mismatched-check-names.cpp               | 2 +-
 .../infrastructure/nolintbeginend-mismatched-delims.cpp     | 2 +-
 .../infrastructure/nolintbeginend-typo-in-check-name.cpp    | 2 +-
 20 files changed, 20 insertions(+), 26 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
index f61e2f40ed03b..949a88f0fd50d 100644
--- a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
+++ b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
@@ -718,11 +718,7 @@ int clangTidyMain(int argc, const char **argv) {
     return 0;
   }
 
-  if (EnabledChecks.empty()) {
-    if (AllowNoChecks) {
-      llvm::outs() << "No checks enabled.\n";
-      return 0;
-    }
+  if (EnabledChecks.empty() && !AllowNoChecks) {
     llvm::errs() << "Error: no checks enabled.\n";
     llvm::cl::PrintHelpMessage(/*Hidden=*/false, /*Categorized=*/true);
     return 1;
diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/allow-no-checks.cpp b/clang-tools-extra/test/clang-tidy/infrastructure/allow-no-checks.cpp
index a1f059b92384d..677ceee75b672 100644
--- a/clang-tools-extra/test/clang-tidy/infrastructure/allow-no-checks.cpp
+++ b/clang-tools-extra/test/clang-tidy/infrastructure/allow-no-checks.cpp
@@ -1,4 +1,2 @@
 // RUN: not clang-tidy %s -checks='-*'
-// RUN: clang-tidy %s -checks='-*' --allow-no-checks | FileCheck --match-full-lines %s
-
-// CHECK: No checks enabled.
+// RUN: clang-tidy %s -checks='-*' --allow-no-checks -- | count 0
diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/header-filter-from-config-file/inheritance/foo.cpp b/clang-tools-extra/test/clang-tidy/infrastructure/header-filter-from-config-file/inheritance/foo.cpp
index 5828c2cafaf7d..79622418d6dff 100644
--- a/clang-tools-extra/test/clang-tidy/infrastructure/header-filter-from-config-file/inheritance/foo.cpp
+++ b/clang-tools-extra/test/clang-tidy/infrastructure/header-filter-from-config-file/inheritance/foo.cpp
@@ -1,3 +1,3 @@
-// RUN: clang-tidy -checks=-*,google-explicit-constructor %s 2>&1 | FileCheck %s
+// RUN: clang-tidy -checks=-*,google-explicit-constructor %s -- 2>&1 | FileCheck %s
 #include "foo.h"
 // CHECK: foo.h:1:12: warning: single-argument constructors must be marked explicit
diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/header-filter-from-config-file/simple/foo.cpp b/clang-tools-extra/test/clang-tidy/infrastructure/header-filter-from-config-file/simple/foo.cpp
index 5828c2cafaf7d..79622418d6dff 100644
--- a/clang-tools-extra/test/clang-tidy/infrastructure/header-filter-from-config-file/simple/foo.cpp
+++ b/clang-tools-extra/test/clang-tidy/infrastructure/header-filter-from-config-file/simple/foo.cpp
@@ -1,3 +1,3 @@
-// RUN: clang-tidy -checks=-*,google-explicit-constructor %s 2>&1 | FileCheck %s
+// RUN: clang-tidy -checks=-*,google-explicit-constructor %s -- 2>&1 | FileCheck %s
 #include "foo.h"
 // CHECK: foo.h:1:12: warning: single-argument constructors must be marked explicit
diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-LIFO.cpp b/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-LIFO.cpp
index e86b3df34fcfc..95e2f698e867e 100644
--- a/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-LIFO.cpp
+++ b/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-LIFO.cpp
@@ -1,4 +1,4 @@
-// RUN: not clang-tidy %s --checks='-*,google-explicit-constructor,modernize-avoid-c-style-cast' 2>&1 | FileCheck %s
+// RUN: not clang-tidy %s --checks='-*,google-explicit-constructor,modernize-avoid-c-style-cast' -- 2>&1 | FileCheck %s
 
 // NOLINTBEGIN(google-explicit-constructor)
 // NOLINTBEGIN(modernize-avoid-c-style-cast)
diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-all-end-glob.cpp b/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-all-end-glob.cpp
index 90b9fa9883024..4e17e809690fc 100644
--- a/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-all-end-glob.cpp
+++ b/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-all-end-glob.cpp
@@ -1,4 +1,4 @@
-// RUN: not clang-tidy %s --checks='-*,google-explicit-constructor' 2>&1 | FileCheck %s
+// RUN: not clang-tidy %s --checks='-*,google-explicit-constructor' -- 2>&1 | FileCheck %s
 
 // NOLINTBEGIN
 class B { B(int i); };
diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-all-end-specific.cpp b/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-all-end-specific.cpp
index 6ffa914e4ef0b..07e430f4b5dab 100644
--- a/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-all-end-specific.cpp
+++ b/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-all-end-specific.cpp
@@ -1,4 +1,4 @@
-// RUN: not clang-tidy %s --checks='-*,google-explicit-constructor' 2>&1 | FileCheck %s
+// RUN: not clang-tidy %s --checks='-*,google-explicit-constructor' -- 2>&1 | FileCheck %s
 
 // NOLINTBEGIN
 class A { A(int i); };
diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-at-eof.cpp b/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-at-eof.cpp
index 0d3dcf381eaba..860a4f9dd0ab7 100644
--- a/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-at-eof.cpp
+++ b/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-at-eof.cpp
@@ -1,4 +1,4 @@
-// RUN: not clang-tidy %s --checks='-*,google-explicit-constructor' 2>&1 | FileCheck %s
+// RUN: not clang-tidy %s --checks='-*,google-explicit-constructor' -- 2>&1 | FileCheck %s
 
 // CHECK: :[[@LINE+8]]:11: warning: single-argument constructors must be marked explicit
 // Note: the expected output has been split over several lines so that clang-tidy
diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-glob-end-all.cpp b/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-glob-end-all.cpp
index 3697d5c11e2e2..b2722071135ed 100644
--- a/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-glob-end-all.cpp
+++ b/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-glob-end-all.cpp
@@ -1,4 +1,4 @@
-// RUN: not clang-tidy %s --checks="-*,google-explicit-constructor" 2>&1 | FileCheck %s
+// RUN: not clang-tidy %s --checks="-*,google-explicit-constructor" -- 2>&1 | FileCheck %s
 
 // NOLINTBEGIN(*)
 class B { B(int i); };
diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-glob-end-specific.cpp b/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-glob-end-specific.cpp
index 5bdb117f20242..dc282aa01424f 100644
--- a/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-glob-end-specific.cpp
+++ b/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-glob-end-specific.cpp
@@ -1,4 +1,4 @@
-// RUN: not clang-tidy %s --checks="-*,google-explicit-constructor" 2>&1 | FileCheck %s
+// RUN: not clang-tidy %s --checks="-*,google-explicit-constructor" -- 2>&1 | FileCheck %s
 
 // NOLINTBEGIN(*)
 class B { B(int i); };
diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-multiple-end-single.cpp b/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-multiple-end-single.cpp
index 156a5cb345dbd..640c25d245e9b 100644
--- a/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-multiple-end-single.cpp
+++ b/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-multiple-end-single.cpp
@@ -1,4 +1,4 @@
-// RUN: not clang-tidy %s --checks='-*,google-explicit-constructor,modernize-avoid-c-style-cast' 2>&1 | FileCheck %s
+// RUN: not clang-tidy %s --checks='-*,google-explicit-constructor,modernize-avoid-c-style-cast' -- 2>&1 | FileCheck %s
 
 // NOLINTBEGIN(google-explicit-constructor,modernize-avoid-c-style-cast)
 class B { B(int i); };
diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-single-end-multiple.cpp b/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-single-end-multiple.cpp
index 837213227dc2d..7de57dda9ea1d 100644
--- a/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-single-end-multiple.cpp
+++ b/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-single-end-multiple.cpp
@@ -1,4 +1,4 @@
-// RUN: not clang-tidy %s --checks='-*,google-explicit-constructor,modernize-avoid-c-style-cast' 2>&1 | FileCheck %s
+// RUN: not clang-tidy %s --checks='-*,google-explicit-constructor,modernize-avoid-c-style-cast' -- 2>&1 | FileCheck %s
 
 // NOLINTBEGIN(google-explicit-constructor)
 // NOLINTBEGIN(modernize-avoid-c-style-cast)
diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-specific-end-all.cpp b/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-specific-end-all.cpp
index decfe2dd5a4c1..34c431013f0fc 100644
--- a/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-specific-end-all.cpp
+++ b/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-specific-end-all.cpp
@@ -1,4 +1,4 @@
-// RUN: not clang-tidy %s --checks="-*,google-explicit-constructor" 2>&1 | FileCheck %s
+// RUN: not clang-tidy %s --checks="-*,google-explicit-constructor" -- 2>&1 | FileCheck %s
 
 // NOLINTBEGIN(google-explicit-constructor)
 class A { A(int i); };
diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-specific-end-glob.cpp b/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-specific-end-glob.cpp
index a9f904ccce138..8e9c9c6df0a79 100644
--- a/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-specific-end-glob.cpp
+++ b/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-specific-end-glob.cpp
@@ -1,4 +1,4 @@
-// RUN: not clang-tidy %s --checks="-*,google-explicit-constructor" 2>&1 | FileCheck %s
+// RUN: not clang-tidy %s --checks="-*,google-explicit-constructor" -- 2>&1 | FileCheck %s
 
 // NOLINTBEGIN(google-explicit-constructor)
 class A { A(int i); };
diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-without-end.cpp b/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-without-end.cpp
index 2cb84ae59775d..1d3a0646cf3e2 100644
--- a/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-without-end.cpp
+++ b/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-without-end.cpp
@@ -1,4 +1,4 @@
-// RUN: not clang-tidy %s --checks='-*,google-explicit-constructor' 2>&1 | FileCheck %s
+// RUN: not clang-tidy %s --checks='-*,google-explicit-constructor' -- 2>&1 | FileCheck %s
 
 // NOLINTBEGIN
 class A { A(int i); };
diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-end-at-sof.cpp b/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-end-at-sof.cpp
index 72b8ac9256866..72d1596cac961 100644
--- a/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-end-at-sof.cpp
+++ b/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-end-at-sof.cpp
@@ -9,4 +9,4 @@ class A { A(int i); };
 // CHECK: TBEGIN' comment [clang-tidy-nolint]
 // CHECK: :[[@LINE-8]]:11: warning: single-argument constructors must be marked explicit
 
-// RUN: not clang-tidy %s --checks='-*,google-explicit-constructor' 2>&1 | FileCheck %s
+// RUN: not clang-tidy %s --checks='-*,google-explicit-constructor' -- 2>&1 | FileCheck %s
diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-end-without-begin.cpp b/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-end-without-begin.cpp
index cea16610823dd..653926f8c2c1c 100644
--- a/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-end-without-begin.cpp
+++ b/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-end-without-begin.cpp
@@ -1,4 +1,4 @@
-// RUN: not clang-tidy %s --checks='-*,google-explicit-constructor' 2>&1 | FileCheck %s
+// RUN: not clang-tidy %s --checks='-*,google-explicit-constructor' -- 2>&1 | FileCheck %s
 
 // NOLINTEND
 class A { A(int i); };
diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-mismatched-check-names.cpp b/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-mismatched-check-names.cpp
index ddd399dfc764f..e54f34646f02c 100644
--- a/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-mismatched-check-names.cpp
+++ b/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-mismatched-check-names.cpp
@@ -1,4 +1,4 @@
-// RUN: not clang-tidy %s --checks='-*,google-explicit-constructor,modernize-avoid-c-style-cast' 2>&1 | FileCheck %s
+// RUN: not clang-tidy %s --checks='-*,google-explicit-constructor,modernize-avoid-c-style-cast' -- 2>&1 | FileCheck %s
 
 // NOLINTBEGIN(google-explicit-constructor)
 class A { A(int i); };
diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-mismatched-delims.cpp b/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-mismatched-delims.cpp
index 4b8947e369f92..b913ef03ebb28 100644
--- a/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-mismatched-delims.cpp
+++ b/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-mismatched-delims.cpp
@@ -1,4 +1,4 @@
-// RUN: not clang-tidy %s --checks='-*,google-explicit-constructor' 2>&1 | FileCheck %s
+// RUN: not clang-tidy %s --checks='-*,google-explicit-constructor' -- 2>&1 | FileCheck %s
 
 // NOLINTBEGIN
 // NOLINTBEGIN
diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-typo-in-check-name.cpp b/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-typo-in-check-name.cpp
index 57e1ff331c8ba..13580cfbea8e5 100644
--- a/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-typo-in-check-name.cpp
+++ b/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-typo-in-check-name.cpp
@@ -1,4 +1,4 @@
-// RUN: not clang-tidy %s --checks='-*,google-explicit-constructor' 2>&1 | FileCheck %s
+// RUN: not clang-tidy %s --checks='-*,google-explicit-constructor' -- 2>&1 | FileCheck %s
 
 // NOLINTBEGIN(google-explicit-constructor)
 class A { A(int i); };



More information about the cfe-commits mailing list