diff --git a/clang-tools-extra/clang-tidy/ClangTidy.cpp b/clang-tools-extra/clang-tidy/ClangTidy.cpp --- a/clang-tools-extra/clang-tidy/ClangTidy.cpp +++ b/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); } diff --git a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp --- a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp +++ b/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); } diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/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, using `Checks` (`--checks=`) as the filter. Use + `-Werror=` on the compiler command-line for custom error promotion + irrespective of `Checks` (`--checks=`) settings. + New checks ^^^^^^^^^^ diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/warnings-as-errors-diagnostics.cpp b/clang-tools-extra/test/clang-tidy/infrastructure/warnings-as-errors-diagnostics.cpp --- a/clang-tools-extra/test/clang-tidy/infrastructure/warnings-as-errors-diagnostics.cpp +++ b/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).