[clang-tidy] Ignore variable template partial specializations in misc-definitions-in-headers
Variable template partial specializations are inline and can't lead to ODR-violations. The checker now ignores them. Fixes https://github.com/llvm/llvm-project/issues/53519 Reviewed By: hokein Differential Revision: https://reviews.llvm.org/D119098
This commit is contained in:
parent
7dd7ccd224
commit
fc84ebfff3
|
@ -149,6 +149,9 @@ void DefinitionsInHeadersCheck::check(const MatchFinder::MatchResult &Result) {
|
|||
// Ignore inline variables.
|
||||
if (VD->isInline())
|
||||
return;
|
||||
// Ignore partial specializations.
|
||||
if (isa<VarTemplatePartialSpecializationDecl>(VD))
|
||||
return;
|
||||
|
||||
diag(VD->getLocation(),
|
||||
"variable %0 defined in a header file; "
|
||||
|
|
|
@ -193,6 +193,16 @@ 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; }
|
||||
|
||||
template <typename T1, typename T2>
|
||||
constexpr bool f13 = false;
|
||||
|
||||
template <typename T>
|
||||
constexpr bool f13<T, int> = true; // OK: template partial specialization
|
||||
|
||||
template <>
|
||||
constexpr bool f13<void, int> = false;
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: variable 'f13<void, int>' defined in a header file;
|
||||
|
||||
int main() {}
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'main' defined in a header file;
|
||||
// CHECK-FIXES: {{^}}int main() {
|
||||
|
|
Loading…
Reference in a new issue