[PATCH] D62524: [clang-tidy] Fix description for misc-definitions-in-headers.
Haojian Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue May 28 07:09:16 PDT 2019
hokein created this revision.
hokein added a reviewer: gribozavr.
Herald added a subscriber: xazax.hun.
Herald added a project: clang.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D62524
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
@@ -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 'inline'
// CHECK-FIXES: inline int f() {
return 1;
}
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
@@ -124,13 +124,16 @@
}
}
- 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 '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())
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62524.201661.patch
Type: text/x-patch
Size: 1881 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190528/5d7da942/attachment.bin>
More information about the cfe-commits
mailing list