[clang-tools-extra] [clang-tidy] Add an option to treat warnings as errors (PR #128221)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 14 08:33:12 PDT 2025
https://github.com/juru1234 updated https://github.com/llvm/llvm-project/pull/128221
>From 968350e01d4a0407d58b89c8859c3c6ec7f42f15 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] Add an option to treat warnings as errors
This patch allows to treat warnings as erros using clang-tidy-diff.
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 41ff1c1016f25..8d016307fba83 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -88,6 +88,9 @@ Improvements to clang-query
Improvements to clang-tidy
--------------------------
+- Improved :program:`clang-tidy-diff.py` script. Add the `-warnings-as-errors`
+ to treat warnings as errors.
+
New checks
^^^^^^^^^^
More information about the cfe-commits
mailing list