diff --git a/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp b/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp --- a/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp +++ b/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp @@ -132,8 +132,7 @@ << IsFullSpec << FD; diag(FD->getLocation(), /*FixDescription=*/"make as 'inline'", DiagnosticIDs::Note) - << FixItHint::CreateInsertion(FD->getReturnTypeSourceRange().getBegin(), - "inline "); + << FixItHint::CreateInsertion(FD->getInnerLocStart(), "inline "); } else if (const auto *VD = dyn_cast(ND)) { // Static data members of a class template are allowed. if (VD->getDeclContext()->isDependentContext() && VD->isStaticDataMember()) diff --git a/clang-tools-extra/test/clang-tidy/misc-definitions-in-headers.hpp b/clang-tools-extra/test/clang-tidy/misc-definitions-in-headers.hpp --- a/clang-tools-extra/test/clang-tidy/misc-definitions-in-headers.hpp +++ b/clang-tools-extra/test/clang-tidy/misc-definitions-in-headers.hpp @@ -180,3 +180,15 @@ constexpr int k = 1; // OK: constexpr variable has internal linkage. constexpr int f10() { return 0; } // OK: constexpr function definition. + +const int f11() { return 0; } +// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: function 'f11' defined in a header file; +// CHECK-FIXES: inline const int f11() { return 0; } + +template +const T f12(); + +template <> +const int f12() { return 0; } +// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: full function template specialization 'f12' defined in a header file; +// CHECK-FIXES: inline const int f12() { return 0; }