[PATCH] Deduplicate clang-tidy error messages by file, offset and message.

Manuel Klimek klimek at google.com
Thu Mar 6 09:23:05 PST 2014


On Mar 6, 2014 6:16 PM, "Alexander Kornienko" <alexfh at google.com> wrote:
>
> Hi djasper, pcc,
>
> Peter, I guess, this can help you in testing your check.
>
> http://llvm-reviews.chandlerc.com/D2989
>
> Files:
>   clang-tidy/ClangTidyDiagnosticConsumer.cpp
>   test/clang-tidy/deduplication.cpp
>
> Index: clang-tidy/ClangTidyDiagnosticConsumer.cpp
> ===================================================================
> --- clang-tidy/ClangTidyDiagnosticConsumer.cpp
> +++ clang-tidy/ClangTidyDiagnosticConsumer.cpp
> @@ -19,6 +19,8 @@
>  #include "ClangTidyDiagnosticConsumer.h"
>  #include "llvm/ADT/SmallString.h"
>
> +#include <set>
> +
>  namespace clang {
>  namespace tidy {
>
> @@ -116,11 +118,37 @@
>    }
>  }
>
> +struct LessClangTidyError {
> +  bool operator()(const ClangTidyError *LHS, const ClangTidyError *RHS)
const {
> +    const ClangTidyMessage &M1 = LHS->Message;
> +    const ClangTidyMessage &M2 = RHS->Message;
> +
> +    if (M1.FileOffset < M2.FileOffset)
> +      return true;
> +    if (M1.FileOffset > M2.FileOffset)
> +      return false;

I'd write those as:
If (a != b)
  Return a < b;

> +    int Result = M1.FilePath.compare(M2.FilePath);
> +    if (Result < 0)
> +      return true;
> +    if (Result > 0)
> +      return false;

Same here.

> +    Result = M1.Message.compare(M2.Message);
> +    if (Result < 0)
> +      return true;
> +    if (Result > 0)
> +      return false;
> +    return false;

Return result < 0;

> +  }
> +};
> +
>  // 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();
>  }
>
> Index: test/clang-tidy/deduplication.cpp
> ===================================================================
> --- /dev/null
> +++ test/clang-tidy/deduplication.cpp
> @@ -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;
> +}
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140306/4bc7aaa2/attachment.html>


More information about the cfe-commits mailing list