[PATCH] D146520: [clang-tidy] Fix checks filter with warnings-as-errors

Piotr Zegar via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Jul 22 12:33:09 PDT 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rG9644368f974a: [clang-tidy] Fix checks filter with warnings-as-errors (authored by PiotrZSL).

Changed prior to commit:
  https://reviews.llvm.org/D146520?vs=543185&id=543222#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146520/new/

https://reviews.llvm.org/D146520

Files:
  clang-tools-extra/clang-tidy/ClangTidy.cpp
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/infrastructure/warnings-as-errors-diagnostics.cpp


Index: clang-tools-extra/test/clang-tidy/infrastructure/warnings-as-errors-diagnostics.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/infrastructure/warnings-as-errors-diagnostics.cpp
+++ clang-tools-extra/test/clang-tidy/infrastructure/warnings-as-errors-diagnostics.cpp
@@ -1,12 +1,15 @@
-// RUN: clang-tidy %s -checks='-*,llvm-namespace-comment,clang-diagnostic*' \
+// RUN: clang-tidy %s --checks='-*,llvm-namespace-comment,clang-diagnostic*' \
 // RUN:   -- -Wunused-variable 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=CHECK-WARN -implicit-check-not='{{warning|error}}:'
-// RUN: not clang-tidy %s -checks='-*,llvm-namespace-comment,clang-diagnostic*' \
-// RUN:   -warnings-as-errors='clang-diagnostic*' -- -Wunused-variable 2>&1 \
+// RUN: not clang-tidy %s --checks='-*,llvm-namespace-comment,clang-diagnostic*' \
+// RUN:   --warnings-as-errors='clang-diagnostic*' -- -Wunused-variable 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=CHECK-WERR -implicit-check-not='{{warning|error}}:'
-// RUN: not clang-tidy %s -checks='-*,llvm-namespace-comment,clang-diagnostic*' \
-// RUN:   -warnings-as-errors='clang-diagnostic*' -quiet -- -Wunused-variable 2>&1 \
+// RUN: not clang-tidy %s --checks='-*,llvm-namespace-comment,clang-diagnostic*' \
+// RUN:   --warnings-as-errors='clang-diagnostic*' -quiet -- -Wunused-variable 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=CHECK-WERR-QUIET -implicit-check-not='{{warning|error}}:'
+// RUN: clang-tidy %s --checks='-*,llvm-namespace-comment' --warnings-as-errors=* -- \
+// RUN:   -Wunused-variable 2>&1 | FileCheck %s --check-prefix=CHECK-SUPPRESSED \
+// RUN:   -implicit-check-not='{{warning|error}}:'
 
 void f() { int i; }
 // CHECK-WARN: warning: unused variable 'i' [clang-diagnostic-unused-variable]
@@ -16,3 +19,7 @@
 // CHECK-WARN-NOT: treated as
 // CHECK-WERR: 1 warning treated as error
 // CHECK-WERR-QUIET-NOT: treated as
+
+// CHECK-SUPPRESSED-NOT: unused variable 'i'
+// CHECK-SUPPRESSED: 1 warning generated.
+// CHECK-SUPPRESSED: Suppressed 1 warnings (1 with check filters).
Index: clang-tools-extra/docs/ReleaseNotes.rst
===================================================================
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -106,6 +106,11 @@
 - Support specifying `SystemHeaders` in the `.clang-tidy` configuration file,
   with the same functionality as the command-line option `--system-headers`.
 
+- `WarningsAsErrors` (`--warnings-as-errors=`) no longer promotes unlisted
+  warnings to errors. Only the warnings listed in `Checks` (`--checks=`) will
+  be promoted to errors. For custom error promotion, use `-Werror=<warning>`
+  on the compiler command-line, irrespective of `Checks` (`--checks=`) settings.
+
 New checks
 ^^^^^^^^^^
 
Index: clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
===================================================================
--- clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -421,8 +421,6 @@
 
     bool IsWarningAsError = DiagLevel == DiagnosticsEngine::Warning &&
                             Context.treatAsError(CheckName);
-    if (IsWarningAsError)
-      Level = ClangTidyError::Error;
     Errors.emplace_back(CheckName, Level, Context.getCurrentBuildDirectory(),
                         IsWarningAsError);
   }
Index: clang-tools-extra/clang-tidy/ClangTidy.cpp
===================================================================
--- clang-tools-extra/clang-tidy/ClangTidy.cpp
+++ clang-tools-extra/clang-tidy/ClangTidy.cpp
@@ -620,6 +620,8 @@
   TUD.MainSourceFile = std::string(MainFilePath);
   for (const auto &Error : Errors) {
     tooling::Diagnostic Diag = Error;
+    if (Error.IsWarningAsError)
+      Diag.DiagLevel = tooling::Diagnostic::Error;
     TUD.Diagnostics.insert(TUD.Diagnostics.end(), Diag);
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146520.543222.patch
Type: text/x-patch
Size: 3967 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230722/d16d882a/attachment.bin>


More information about the cfe-commits mailing list