diff options
author | Alexander Kornienko <alexfh@google.com> | 2018-11-27 10:53:44 +0000 |
---|---|---|
committer | Alexander Kornienko <alexfh@google.com> | 2018-11-27 10:53:44 +0000 |
commit | 27011d1db0ee4955bab595ab51ebe264e160ed89 (patch) | |
tree | 1ae0797474da124ead34bd8762c9089d7ea80b8d /clang-tidy/readability | |
parent | cb0512a7ecb72f4167bd98e57b1d06ed2dc2556b (diff) |
[clang-tidy] Avoid inconsistent notes in readability-container-size-empty
When a warning is issued in a template instantiation, the check would previously
use template arguments in a note, which would result in inconsistent or
duplicate warnings (depending on how deduplication was done). This patch removes
template arguments from the note.
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@347652 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'clang-tidy/readability')
-rw-r--r-- | clang-tidy/readability/ContainerSizeEmptyCheck.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/clang-tidy/readability/ContainerSizeEmptyCheck.cpp b/clang-tidy/readability/ContainerSizeEmptyCheck.cpp index 60a153a8..97f9eb71 100644 --- a/clang-tidy/readability/ContainerSizeEmptyCheck.cpp +++ b/clang-tidy/readability/ContainerSizeEmptyCheck.cpp @@ -213,6 +213,14 @@ void ContainerSizeEmptyCheck::check(const MatchFinder::MatchResult &Result) { } const auto *Container = Result.Nodes.getNodeAs<NamedDecl>("container"); + if (const auto *CTS = dyn_cast<ClassTemplateSpecializationDecl>(Container)) { + // The definition of the empty() method is the same for all implicit + // instantiations. In order to avoid duplicate or inconsistent warnings + // (depending on how deduplication is done), we use the same class name + // for all implicit instantiations of a template. + if (CTS->getSpecializationKind() == TSK_ImplicitInstantiation) + Container = CTS->getSpecializedTemplate(); + } const auto *Empty = Result.Nodes.getNodeAs<FunctionDecl>("empty"); diag(Empty->getLocation(), "method %0::empty() defined here", |