[clang-tidy] Fix definitions in headers check to respect qualifiers

Summary:
The check was generating a fix without taking qualifiers in return type
into account. This patch changes the insertion location to be before qualifers.

Reviewers: gribozavr

Subscribers: xazax.hun, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D67213

llvm-svn: 371022
This commit is contained in:
Kadir Cetinkaya 2019-09-05 08:11:21 +00:00
parent caa42792f3
commit 4a16c29551
2 changed files with 13 additions and 2 deletions

View File

@ -132,8 +132,7 @@ void DefinitionsInHeadersCheck::check(const MatchFinder::MatchResult &Result) {
<< 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<VarDecl>(ND)) {
// Static data members of a class template are allowed.
if (VD->getDeclContext()->isDependentContext() && VD->isStaticDataMember())

View File

@ -180,3 +180,15 @@ int CD<T, int>::f() { // OK: partial template specialization.
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 <typename T>
const T f12();
template <>
const int f12() { return 0; }
// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: full function template specialization 'f12<int>' defined in a header file;
// CHECK-FIXES: inline const int f12() { return 0; }