This revision was automatically updated to reflect the committed changes. Closed by commit rL295178: [clang-tidy] Ignore instantiated functions and static data members of classes… (authored by hokein).
Changed prior to commit: https://reviews.llvm.org/D29957?vs=88413&id=88520#toc Repository: rL LLVM https://reviews.llvm.org/D29957 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/clang-tidy/misc/DefinitionsInHeadersCheck.cpp =================================================================== --- clang-tools-extra/trunk/clang-tidy/misc/DefinitionsInHeadersCheck.cpp +++ clang-tools-extra/trunk/clang-tidy/misc/DefinitionsInHeadersCheck.cpp @@ -104,8 +104,8 @@ // Function templates are allowed. if (FD->getTemplatedKind() == FunctionDecl::TK_FunctionTemplate) return; - // Function template full specialization is prohibited in header file. - if (FD->getTemplateSpecializationKind() == TSK_ImplicitInstantiation) + // Ignore instantiated functions. + if (FD->isTemplateInstantiation()) return; // Member function of a class template and member function of a nested class // in a class template are allowed. @@ -133,7 +133,8 @@ // Static data members of a class template are allowed. if (VD->getDeclContext()->isDependentContext() && VD->isStaticDataMember()) return; - if (VD->getTemplateSpecializationKind() == TSK_ImplicitInstantiation) + // Ignore instantiated static data members of classes. + if (isTemplateInstantiation(VD->getTemplateSpecializationKind())) return; // Ignore variable definition within function scope. if (VD->hasLocalStorage() || VD->isStaticLocal()) 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 @@ -71,6 +71,12 @@ template <typename T> int CB<T>::a = 2; // OK: static data member definition of a class template. +template class CB<int>; // OK: explicitly instantiated static data member of a class template. +inline int callCB() { + CB<double> cb; // OK: implicitly instantiated static data member of a class template. + return cb.a; +} + template <typename T> T tf() { // OK: template function definition. T a; @@ -107,6 +113,12 @@ int f8() = delete; // OK: the function being marked delete is not callable. +template <typename T> +int f9(T t) { return 1; } + +inline void callF9() { f9(1); } // OK: implicitly instantiated function. +template int f9(double); // OK: explicitly instantiated function. + int a = 1; // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: variable 'a' defined in a header file; variable definitions in header files can lead to ODR violations [misc-definitions-in-headers] CA a1;
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 @@ -104,8 +104,8 @@ // Function templates are allowed. if (FD->getTemplatedKind() == FunctionDecl::TK_FunctionTemplate) return; - // Function template full specialization is prohibited in header file. - if (FD->getTemplateSpecializationKind() == TSK_ImplicitInstantiation) + // Ignore instantiated functions. + if (FD->isTemplateInstantiation()) return; // Member function of a class template and member function of a nested class // in a class template are allowed. @@ -133,7 +133,8 @@ // Static data members of a class template are allowed. if (VD->getDeclContext()->isDependentContext() && VD->isStaticDataMember()) return; - if (VD->getTemplateSpecializationKind() == TSK_ImplicitInstantiation) + // Ignore instantiated static data members of classes. + if (isTemplateInstantiation(VD->getTemplateSpecializationKind())) return; // Ignore variable definition within function scope. if (VD->hasLocalStorage() || VD->isStaticLocal()) 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 @@ -71,6 +71,12 @@ template <typename T> int CB<T>::a = 2; // OK: static data member definition of a class template. +template class CB<int>; // OK: explicitly instantiated static data member of a class template. +inline int callCB() { + CB<double> cb; // OK: implicitly instantiated static data member of a class template. + return cb.a; +} + template <typename T> T tf() { // OK: template function definition. T a; @@ -107,6 +113,12 @@ int f8() = delete; // OK: the function being marked delete is not callable. +template <typename T> +int f9(T t) { return 1; } + +inline void callF9() { f9(1); } // OK: implicitly instantiated function. +template int f9(double); // OK: explicitly instantiated function. + int a = 1; // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: variable 'a' defined in a header file; variable definitions in header files can lead to ODR violations [misc-definitions-in-headers] CA a1;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits