[clang-tidy] Suppress notes for warnings that were ignored
Fixes PR30565. Patch by Nikita Kakuev llvm-svn: 285861
This commit is contained in:
parent
fbebe1632a
commit
cb2e749e46
|
@ -250,7 +250,7 @@ StringRef ClangTidyContext::getCheckName(unsigned DiagnosticID) const {
|
|||
|
||||
ClangTidyDiagnosticConsumer::ClangTidyDiagnosticConsumer(ClangTidyContext &Ctx)
|
||||
: Context(Ctx), LastErrorRelatesToUserCode(false),
|
||||
LastErrorPassesLineFilter(false) {
|
||||
LastErrorPassesLineFilter(false), LastErrorWasIgnored(false) {
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
|
||||
Diags.reset(new DiagnosticsEngine(
|
||||
IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs), &*DiagOpts, this,
|
||||
|
@ -309,13 +309,20 @@ static bool LineIsMarkedWithNOLINTinMacro(SourceManager &SM,
|
|||
|
||||
void ClangTidyDiagnosticConsumer::HandleDiagnostic(
|
||||
DiagnosticsEngine::Level DiagLevel, const Diagnostic &Info) {
|
||||
if (LastErrorWasIgnored && DiagLevel == DiagnosticsEngine::Note)
|
||||
return;
|
||||
|
||||
if (Info.getLocation().isValid() &&
|
||||
DiagLevel != DiagnosticsEngine::Error &&
|
||||
DiagLevel != DiagnosticsEngine::Fatal &&
|
||||
LineIsMarkedWithNOLINTinMacro(Diags->getSourceManager(), Info.getLocation())) {
|
||||
++Context.Stats.ErrorsIgnoredNOLINT;
|
||||
// Ignored a warning, should ignore related notes as well
|
||||
LastErrorWasIgnored = true;
|
||||
return;
|
||||
}
|
||||
|
||||
LastErrorWasIgnored = false;
|
||||
// Count warnings/errors.
|
||||
DiagnosticConsumer::HandleDiagnostic(DiagLevel, Info);
|
||||
|
||||
|
|
|
@ -286,6 +286,7 @@ private:
|
|||
std::unique_ptr<llvm::Regex> HeaderFilter;
|
||||
bool LastErrorRelatesToUserCode;
|
||||
bool LastErrorPassesLineFilter;
|
||||
bool LastErrorWasIgnored;
|
||||
};
|
||||
|
||||
} // end namespace tidy
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
void A1(const int &In, int &Out) {
|
||||
if (In > 123) // NOLINT
|
||||
Out = 123;
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
// RUN: %check_clang_tidy %s google-explicit-constructor,clang-diagnostic-unused-variable %t -- -extra-arg=-Wunused-variable --
|
||||
// RUN: %check_clang_tidy %s google-explicit-constructor,clang-diagnostic-unused-variable,clang-analyzer-core.UndefinedBinaryOperatorResult %t -- -extra-arg=-Wunused-variable -- -I%S/Inputs/nolint
|
||||
|
||||
|
||||
class A { A(int i); };
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: single-argument constructors must be marked explicit
|
||||
|
@ -27,4 +28,12 @@ MACRO_NOLINT
|
|||
#define DOUBLE_MACRO MACRO(H) // NOLINT
|
||||
DOUBLE_MACRO
|
||||
|
||||
// CHECK-MESSAGES: Suppressed 7 warnings (7 NOLINT)
|
||||
#include "trigger_warning.h"
|
||||
void I(int& Out) {
|
||||
int In;
|
||||
A1(In, Out);
|
||||
}
|
||||
// CHECK-NOT: trigger_warning.h:{{.*}} warning: The left operand of '>' is a garbage value
|
||||
// CHECK-NOT: :[[@LINE-4]]:{{.*}} note
|
||||
|
||||
// CHECK-MESSAGES: Suppressed 8 warnings (8 NOLINT)
|
||||
|
|
Loading…
Reference in New Issue