llvm-project/clang-tools-extra/test/clang-tidy/infrastructure/warnings-as-errors-diagnostics.cpp
Piotr Zegar 9644368f97 [clang-tidy] Fix checks filter with warnings-as-errors
Since commit 5d12b13b0b26bc58b02ee23c369da8b83240cceb, warnings are
internally classified as errors which skip the check filters.

One use-case is particularly affected: you cannot selectively disable
clang-analyzer-core checks, they are force-enabled because required by others.
So enabling warning as errors will show new (and unwanted) errors !

Co-authored-by: kiwixz <kiwixz@outlook.com>

Fixes: #61969

Reviewed By: carlosgalvezp

Differential Revision: https://reviews.llvm.org/D146520
2023-07-22 19:31:51 +00:00

26 lines
1.5 KiB
C++

// 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: | 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: | 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]
// CHECK-WERR: error: unused variable 'i' [clang-diagnostic-unused-variable,-warnings-as-errors]
// CHECK-WERR-QUIET: error: unused variable 'i' [clang-diagnostic-unused-variable,-warnings-as-errors]
// 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).