[PATCH] D22260: [clang-tidy] Fix misc-definitions-in-headers misplaced fixing to fully templated function.
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 12 01:09:41 PDT 2016
hokein created this revision.
hokein added a reviewer: alexfh.
hokein added a subscriber: cfe-commits.
http://reviews.llvm.org/D22260
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-FIXES: inline int CA::f3() {
int a = 1;
return a;
}
@@ -90,8 +91,9 @@
}
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 @@
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;
}
Index: clang-tidy/misc/DefinitionsInHeadersCheck.cpp
===================================================================
--- clang-tidy/misc/DefinitionsInHeadersCheck.cpp
+++ clang-tidy/misc/DefinitionsInHeadersCheck.cpp
@@ -126,8 +126,8 @@
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())
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22260.63649.patch
Type: text/x-patch
Size: 1778 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160712/c49a80ac/attachment.bin>
More information about the cfe-commits
mailing list