[clang-tools-extra] r203451 - Deduplicate clang-tidy error messages by file, offset and message.
Alexander Kornienko
alexfh at google.com
Mon Mar 10 02:45:49 PDT 2014
Author: alexfh
Date: Mon Mar 10 04:45:49 2014
New Revision: 203451
URL: http://llvm.org/viewvc/llvm-project?rev=203451&view=rev
Log:
Deduplicate clang-tidy error messages by file, offset and message.
Summary: Peter, I guess, this can help you in testing your check.
Reviewers: djasper, pcc, klimek
Reviewed By: klimek
CC: cfe-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D2989
Added:
clang-tools-extra/trunk/test/clang-tidy/deduplication.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp
Modified: clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp?rev=203451&r1=203450&r2=203451&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp Mon Mar 10 04:45:49 2014
@@ -19,6 +19,9 @@
#include "ClangTidyDiagnosticConsumer.h"
#include "llvm/ADT/SmallString.h"
+#include <set>
+#include <tuple>
+
namespace clang {
namespace tidy {
@@ -116,11 +119,24 @@ void ClangTidyDiagnosticConsumer::Handle
}
}
+struct LessClangTidyError {
+ bool operator()(const ClangTidyError *LHS, const ClangTidyError *RHS) const {
+ const ClangTidyMessage &M1 = LHS->Message;
+ const ClangTidyMessage &M2 = RHS->Message;
+
+ return std::tie(M1.FilePath, M1.FileOffset, M1.Message) <
+ std::tie(M2.FilePath, M2.FileOffset, M2.Message);
+ }
+};
+
// Flushes the internal diagnostics buffer to the ClangTidyContext.
void ClangTidyDiagnosticConsumer::finish() {
finalizeLastError();
- for (const ClangTidyError &Error : Errors)
- Context.storeError(Error);
+ std::set<const ClangTidyError*, LessClangTidyError> UniqueErrors;
+ for (const ClangTidyError &Error : Errors) {
+ if (UniqueErrors.insert(&Error).second)
+ Context.storeError(Error);
+ }
Errors.clear();
}
Added: clang-tools-extra/trunk/test/clang-tidy/deduplication.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/deduplication.cpp?rev=203451&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/deduplication.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/deduplication.cpp Mon Mar 10 04:45:49 2014
@@ -0,0 +1,12 @@
+// RUN: clang-tidy -checks=google-explicit-constructor %s -- | FileCheck %s
+
+template<typename T>
+class A { A(T); };
+// CHECK: :[[@LINE-1]]:11: warning: Single-argument constructors must be explicit [google-explicit-constructor]
+// CHECK-NOT: warning:
+
+
+void f() {
+ A<int> a;
+ A<double> b;
+}
More information about the cfe-commits
mailing list