[clang-tools-extra] r259643 - [clang-tidy] bug fix: Don't warn on partial template specialization in `misc-definitions-in-headers` check.

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 3 04:10:28 PST 2016


Author: hokein
Date: Wed Feb  3 06:10:27 2016
New Revision: 259643

URL: http://llvm.org/viewvc/llvm-project?rev=259643&view=rev
Log:
[clang-tidy] bug fix: Don't warn on partial template specialization in `misc-definitions-in-headers` check.

Reviewers: alexfh

Subscribers: cfe-commits

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

Modified:
    clang-tools-extra/trunk/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
    clang-tools-extra/trunk/test/clang-tidy/misc-definitions-in-headers.hpp

Modified: clang-tools-extra/trunk/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/DefinitionsInHeadersCheck.cpp?rev=259643&r1=259642&r2=259643&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/DefinitionsInHeadersCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/DefinitionsInHeadersCheck.cpp Wed Feb  3 06:10:27 2016
@@ -91,9 +91,12 @@ void DefinitionsInHeadersCheck::check(co
     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();
       }
     }

Modified: clang-tools-extra/trunk/test/clang-tidy/misc-definitions-in-headers.hpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-definitions-in-headers.hpp?rev=259643&r1=259642&r2=259643&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/misc-definitions-in-headers.hpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/misc-definitions-in-headers.hpp Wed Feb  3 06:10:27 2016
@@ -133,3 +133,28 @@ const char* const g = "foo"; // OK: inte
 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;
+}




More information about the cfe-commits mailing list