[PATCH] D67213: [clang-tidy] Fix definitions in headers check to respect qualifiers
Kadir Cetinkaya via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 5 00:16:30 PDT 2019
kadircet created this revision.
kadircet added a reviewer: gribozavr.
Herald added subscribers: cfe-commits, xazax.hun.
Herald added a project: clang.
The check was generating a fix without taking qualifiers in return type
into account. This patch changes the insertion location to be before qualifers.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D67213
Files:
clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
clang-tools-extra/test/clang-tidy/misc-definitions-in-headers.hpp
Index: clang-tools-extra/test/clang-tidy/misc-definitions-in-headers.hpp
===================================================================
--- clang-tools-extra/test/clang-tidy/misc-definitions-in-headers.hpp
+++ 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 <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; }
Index: clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
+++ 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<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: D67213.218851.patch
Type: text/x-patch
Size: 1713 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190905/1b6fd7ae/attachment.bin>
More information about the cfe-commits
mailing list