[clang-tools-extra] r295048 - [clang-tidy] Improve diagnostic message for misc-definitions-in-header.

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 14 04:39:23 PST 2017


Author: hokein
Date: Tue Feb 14 06:39:22 2017
New Revision: 295048

URL: http://llvm.org/viewvc/llvm-project?rev=295048&view=rev
Log:
[clang-tidy] Improve diagnostic message for misc-definitions-in-header.

Summary:
Users might get confused easily when they see the check's message on
full template function speciliations.

Add a note to the output message, which mentions these kind of function
specializations are treated as regular functions.

Reviewers: alexfh

Reviewed By: alexfh

Subscribers: JDevlieghere, cfe-commits

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

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=295048&r1=295047&r2=295048&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/DefinitionsInHeadersCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/DefinitionsInHeadersCheck.cpp Tue Feb 14 06:39:22 2017
@@ -122,10 +122,12 @@ void DefinitionsInHeadersCheck::check(co
       }
     }
 
+    bool is_full_spec = FD->getTemplateSpecializationKind() != TSK_Undeclared;
     diag(FD->getLocation(),
-         "function %0 defined in a header file; "
-         "function definitions in header files can lead to ODR violations")
-        << FD << FixItHint::CreateInsertion(
+         "%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 ");
   } else if (const auto *VD = dyn_cast<VarDecl>(ND)) {
     // Static data members of a class template are allowed.

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=295048&r1=295047&r2=295048&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 Feb 14 06:39:22 2017
@@ -28,7 +28,7 @@ void CA::f2() { }
 
 template <>
 int CA::f3() {
-// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: function 'f3<int>' defined in a header file;
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: full function template specialization 'f3<int>' defined in a header file;
 // CHECK-FIXES: inline int CA::f3() {
   int a = 1;
   return a;
@@ -92,7 +92,7 @@ T f3() {
 
 template <>
 int f3() {
-// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f3<int>' defined in a header file;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: full function template specialization 'f3<int>' defined in a header file;
 // CHECK-FIXES: inline int f3() {
   int a = 1;
   return a;




More information about the cfe-commits mailing list