[PATCH] D16578: [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:14:48 PST 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL259643: [clang-tidy] bug fix: Don't warn on partial template specialization in `misc… (authored by hokein).

Changed prior to commit:
  http://reviews.llvm.org/D16578?vs=45984&id=46767#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D16578

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

Index: clang-tools-extra/trunk/test/clang-tidy/misc-definitions-in-headers.hpp
===================================================================
--- clang-tools-extra/trunk/test/clang-tidy/misc-definitions-in-headers.hpp
+++ clang-tools-extra/trunk/test/clang-tidy/misc-definitions-in-headers.hpp
@@ -133,3 +133,28 @@
 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;
+}
Index: clang-tools-extra/trunk/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
===================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
@@ -91,9 +91,12 @@
     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();
       }
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D16578.46767.patch
Type: text/x-patch
Size: 1700 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160203/707febf7/attachment.bin>


More information about the cfe-commits mailing list