[clang-tools-extra] r361834 - [clang-tidy] Fix description for misc-definitions-in-headers.

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Tue May 28 07:50:43 PDT 2019


Author: hokein
Date: Tue May 28 07:50:42 2019
New Revision: 361834

URL: http://llvm.org/viewvc/llvm-project?rev=361834&view=rev
Log:
[clang-tidy] Fix description for misc-definitions-in-headers.

Reviewers: gribozavr

Subscribers: xazax.hun, cfe-commits

Tags: #clang

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

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

Modified: clang-tools-extra/trunk/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/DefinitionsInHeadersCheck.cpp?rev=361834&r1=361833&r2=361834&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/DefinitionsInHeadersCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/DefinitionsInHeadersCheck.cpp Tue May 28 07:50:42 2019
@@ -124,13 +124,16 @@ void DefinitionsInHeadersCheck::check(co
       }
     }
 
-    bool is_full_spec = FD->getTemplateSpecializationKind() != TSK_Undeclared;
+    bool IsFullSpec = FD->getTemplateSpecializationKind() != TSK_Undeclared;
     diag(FD->getLocation(),
          "%select{function|full function template specialization}0 %1 defined "
          "in a header file; function definitions in header files can lead to "
          "ODR violations")
-        << is_full_spec << FD << FixItHint::CreateInsertion(
-                     FD->getReturnTypeSourceRange().getBegin(), "inline ");
+        << IsFullSpec << FD;
+    diag(FD->getLocation(), /*FixDescription=*/"make as 'inline'",
+         DiagnosticIDs::Note)
+        << 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())

Modified: clang-tools-extra/trunk/test/clang-tidy/misc-definitions-in-headers.hpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-definitions-in-headers.hpp?rev=361834&r1=361833&r2=361834&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/misc-definitions-in-headers.hpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/misc-definitions-in-headers.hpp Tue May 28 07:50:42 2019
@@ -2,6 +2,7 @@
 
 int f() {
 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f' defined in a header file; function definitions in header files can lead to ODR violations [misc-definitions-in-headers]
+// CHECK-MESSAGES: :[[@LINE-2]]:5: note: make as 'inline'
 // CHECK-FIXES: inline int f() {
   return 1;
 }




More information about the cfe-commits mailing list