Skip to content

Commit

Permalink
[clang-tidy] bug fix: Don't warn on partial template specialization i…
Browse files Browse the repository at this point in the history
…n `misc-definitions-in-headers` check.

Reviewers: alexfh

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D16578

llvm-svn: 259643
  • Loading branch information
hokein committed Feb 3, 2016
1 parent 5f496fb commit 29634fe
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Expand Up @@ -91,9 +91,12 @@ void DefinitionsInHeadersCheck::check(const MatchFinder::MatchResult &Result) {
if (const auto *MD = dyn_cast<CXXMethodDecl>(FD)) {
const auto *DC = MD->getDeclContext();
while (DC->isRecord()) {
if (const auto *RD = dyn_cast<CXXRecordDecl>(DC))
if (const auto *RD = dyn_cast<CXXRecordDecl>(DC)) {
if (isa<ClassTemplatePartialSpecializationDecl>(RD))
return;
if (RD->getDescribedClassTemplate())
return;
}
DC = DC->getParent();
}
}
Expand Down
25 changes: 25 additions & 0 deletions clang-tools-extra/test/clang-tidy/misc-definitions-in-headers.hpp
Expand Up @@ -133,3 +133,28 @@ const char* const g = "foo"; // OK: internal linkage variable definition.
static int h = 1; // OK: internal linkage variable definition.
const int i = 1; // OK: internal linkage variable definition.
extern int j; // OK: internal linkage variable definition.

template <typename T, typename U>
struct CD {
int f();
};

template <typename T>
struct CD<T, int> {
int f();
};

template <>
struct CD<int, int> {
int f();
};

int CD<int, int>::f() {
// CHECK-MESSAGES: :[[@LINE-1]]:19: warning: function 'f' defined in a header file;
return 0;
}

template <typename T>
int CD<T, int>::f() { // OK: partial template specialization.
return 0;
}

0 comments on commit 29634fe

Please sign in to comment.