[clang-tidy] Fix misc-definitions-in-headers misplaced fixing to fully templated function.

Reviewers: alexfh, aaron.ballman

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D22260

llvm-svn: 275263
This commit is contained in:
Haojian Wu 2016-07-13 13:55:29 +00:00
parent 57548a6fa6
commit 0b067c1252
2 changed files with 6 additions and 3 deletions

View File

@ -126,8 +126,8 @@ void DefinitionsInHeadersCheck::check(const MatchFinder::MatchResult &Result) {
diag(FD->getLocation(),
"function %0 defined in a header file; "
"function definitions in header files can lead to ODR violations")
<< FD << FixItHint::CreateInsertion(FD->getSourceRange().getBegin(),
"inline ");
<< FD << FixItHint::CreateInsertion(
FD->getReturnTypeSourceRange().getBegin(), "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

@ -29,6 +29,7 @@ void CA::f2() { }
template <>
int CA::f3() {
// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: function 'f3<int>' defined in a header file;
// CHECK-FIXES: inline int CA::f3() {
int a = 1;
return a;
}
@ -90,8 +91,9 @@ T f3() {
}
template <>
// CHECK-MESSAGES: :[[@LINE+1]]:5: warning: function 'f3<int>' defined in a header file;
int f3() {
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f3<int>' defined in a header file;
// CHECK-FIXES: inline int f3() {
int a = 1;
return a;
}
@ -153,6 +155,7 @@ struct CD<int, int> {
int CD<int, int>::f() {
// CHECK-MESSAGES: :[[@LINE-1]]:19: warning: function 'f' defined in a header file;
// CHECK-FIXES: inline int CD<int, int>::f() {
return 0;
}