[clang-tools-extra] [clang-tidy] Add an option to treat warnings as errors (PR #128221)
Julian Ruess via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 14 13:15:34 PDT 2025
https://github.com/juru1234 updated https://github.com/llvm/llvm-project/pull/128221
>From 534f33d19ce72b299789db9a2497ba2b6d5a9e47 Mon Sep 17 00:00:00 2001
From: Julian Ruess <julianonline+github at posteo.de>
Date: Fri, 21 Feb 2025 20:42:46 +0100
Subject: [PATCH] [clang-tidy-diff.py] Add an option to treat warnings as
errors
This patch allows to treat warnings as erros using clang-tidy-diff.py.
Co-authored-by: Piotr Zegar <me at piotrzegar.pl>
---
clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py | 7 +++++++
clang-tools-extra/docs/ReleaseNotes.rst | 3 +++
2 files changed, 10 insertions(+)
diff --git a/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py b/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
index 33de2077dfb1a..0f8ac7344aca3 100755
--- a/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
+++ b/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
@@ -259,6 +259,11 @@ def main():
action="store_true",
help="Only check files in the compilation database",
)
+ parser.add_argument(
+ "-warnings-as-errors",
+ help="Upgrades clang-tidy warnings to errors. Same format as '-checks'.",
+ default="",
+ )
clang_tidy_args = []
argv = sys.argv[1:]
@@ -374,6 +379,8 @@ def main():
common_clang_tidy_args.append("-extra-arg-before=%s" % arg)
for plugin in args.plugins:
common_clang_tidy_args.append("-load=%s" % plugin)
+ if args.warnings_as_errors:
+ common_clang_tidy_args.append("-warnings-as-errors=" + args.warnings_as_errors)
for name in lines_by_file:
line_filter_json = json.dumps(
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index d621a9c6d840b..8e3bfa9e978d1 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -97,6 +97,9 @@ Improvements to clang-tidy
Note: this may lead to false negatives; downstream users may need to adjust
their checks to preserve existing behavior.
+- Improved :program:`clang-tidy-diff.py` script. Add the `-warnings-as-errors`
+ argument to treat warnings as errors.
+
New checks
^^^^^^^^^^
More information about the cfe-commits
mailing list