hokein created this revision. Herald added a subscriber: JDevlieghere. Users might get confused easily when they see the check's message on full template function speciliations.
Add a note to the output message, which mentions these kind of function specializations are treated as regular functions. https://reviews.llvm.org/D29928 Files: clang-tidy/misc/DefinitionsInHeadersCheck.cpp test/clang-tidy/misc-definitions-in-headers.hpp Index: test/clang-tidy/misc-definitions-in-headers.hpp =================================================================== --- test/clang-tidy/misc-definitions-in-headers.hpp +++ test/clang-tidy/misc-definitions-in-headers.hpp @@ -29,6 +29,7 @@ template <> int CA::f3() { // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: function 'f3<int>' defined in a header file; +// CHECK-MESSAGES: :[[@LINE-2]]:9: note: this is a full function template specilization // CHECK-FIXES: inline int CA::f3() { int a = 1; return a; @@ -93,6 +94,7 @@ template <> int f3() { // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f3<int>' defined in a header file; +// CHECK-MESSAGES: :[[@LINE-2]]:5: note: this is a full function template specilization // CHECK-FIXES: inline int f3() { int a = 1; return a; Index: clang-tidy/misc/DefinitionsInHeadersCheck.cpp =================================================================== --- clang-tidy/misc/DefinitionsInHeadersCheck.cpp +++ clang-tidy/misc/DefinitionsInHeadersCheck.cpp @@ -127,6 +127,12 @@ "function definitions in header files can lead to ODR violations") << FD << FixItHint::CreateInsertion( FD->getReturnTypeSourceRange().getBegin(), "inline "); + // Output notes for full function template specializations. + if (FD->getTemplateSpecializationKind() != TSK_Undeclared) + diag(FD->getLocation(), "this is a full function template specilization " + "which behaves as a regular function, so the ODR " + "still applies", + DiagnosticIDs::Note); } else if (const auto *VD = dyn_cast<VarDecl>(ND)) { // Static data members of a class template are allowed. if (VD->getDeclContext()->isDependentContext() && VD->isStaticDataMember())
Index: test/clang-tidy/misc-definitions-in-headers.hpp =================================================================== --- test/clang-tidy/misc-definitions-in-headers.hpp +++ test/clang-tidy/misc-definitions-in-headers.hpp @@ -29,6 +29,7 @@ template <> int CA::f3() { // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: function 'f3<int>' defined in a header file; +// CHECK-MESSAGES: :[[@LINE-2]]:9: note: this is a full function template specilization // CHECK-FIXES: inline int CA::f3() { int a = 1; return a; @@ -93,6 +94,7 @@ template <> int f3() { // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f3<int>' defined in a header file; +// CHECK-MESSAGES: :[[@LINE-2]]:5: note: this is a full function template specilization // CHECK-FIXES: inline int f3() { int a = 1; return a; Index: clang-tidy/misc/DefinitionsInHeadersCheck.cpp =================================================================== --- clang-tidy/misc/DefinitionsInHeadersCheck.cpp +++ clang-tidy/misc/DefinitionsInHeadersCheck.cpp @@ -127,6 +127,12 @@ "function definitions in header files can lead to ODR violations") << FD << FixItHint::CreateInsertion( FD->getReturnTypeSourceRange().getBegin(), "inline "); + // Output notes for full function template specializations. + if (FD->getTemplateSpecializationKind() != TSK_Undeclared) + diag(FD->getLocation(), "this is a full function template specilization " + "which behaves as a regular function, so the ODR " + "still applies", + DiagnosticIDs::Note); } else if (const auto *VD = dyn_cast<VarDecl>(ND)) { // Static data members of a class template are allowed. if (VD->getDeclContext()->isDependentContext() && VD->isStaticDataMember())
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits