[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 Feb 21 11:48:24 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-tidy

Author: Julian (juru1234)

<details>
<summary>Changes</summary>

This patch allows to treat warnings as erros using clang-tidy-diff.

---
Full diff: https://github.com/llvm/llvm-project/pull/128221.diff


1 Files Affected:

- (modified) clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py (+9) 


``````````diff
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..863b504539b58 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,12 @@ 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 +380,9 @@ 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(

``````````

</details>


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


More information about the cfe-commits mailing list