[clang-tidy] Fix definitions in headers check to respect qualifiers
authorKadir Cetinkaya <kadircet@google.com>
Thu, 5 Sep 2019 08:11:21 +0000 (08:11 +0000)
committerKadir Cetinkaya <kadircet@google.com>
Thu, 5 Sep 2019 08:11:21 +0000 (08:11 +0000)
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

clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
clang-tools-extra/test/clang-tidy/misc-definitions-in-headers.hpp

index a496e3b..1d41edd 100644 (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())
index 662b061..25009eb 100644 (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; }