Index: clang-tidy/ClangTidyDiagnosticConsumer.h =================================================================== --- clang-tidy/ClangTidyDiagnosticConsumer.h +++ clang-tidy/ClangTidyDiagnosticConsumer.h @@ -286,6 +286,7 @@ std::unique_ptr HeaderFilter; bool LastErrorRelatesToUserCode; bool LastErrorPassesLineFilter; + bool LastErrorWasIgnored; }; } // end namespace tidy Index: clang-tidy/ClangTidyDiagnosticConsumer.cpp =================================================================== --- clang-tidy/ClangTidyDiagnosticConsumer.cpp +++ clang-tidy/ClangTidyDiagnosticConsumer.cpp @@ -250,7 +250,7 @@ ClangTidyDiagnosticConsumer::ClangTidyDiagnosticConsumer(ClangTidyContext &Ctx) : Context(Ctx), LastErrorRelatesToUserCode(false), - LastErrorPassesLineFilter(false) { + LastErrorPassesLineFilter(false), LastErrorWasIgnored(false) { IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions(); Diags.reset(new DiagnosticsEngine( IntrusiveRefCntPtr(new DiagnosticIDs), &*DiagOpts, this, @@ -309,13 +309,20 @@ 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); Index: test/clang-tidy/Inputs/nolint/trigger_warning.h =================================================================== --- test/clang-tidy/Inputs/nolint/trigger_warning.h +++ test/clang-tidy/Inputs/nolint/trigger_warning.h @@ -0,0 +1,5 @@ +void A1(const int &In, int &Out) { + if (In > 123) // NOLINT + Out = 123; +} + Index: test/clang-tidy/nolint.cpp =================================================================== --- test/clang-tidy/nolint.cpp +++ test/clang-tidy/nolint.cpp @@ -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 @@ #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)