Skip to content

Commit 4781305

Browse files
authored
[clang-tidy] Ignore pure-virtual in portability-template... (#150290)
Ignore pure virtual member functions in portability-template-virtual-member-function check. Those functions will be represented in vtable as __cxa_pure_virtual or something similar. Fixes #139031.
1 parent 20a7902 commit 4781305

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

clang-tools-extra/clang-tidy/portability/TemplateVirtualMemberFunctionCheck.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ AST_MATCHER(CXXMethodDecl, isUsed) { return Node.isUsed(); }
1818

1919
void TemplateVirtualMemberFunctionCheck::registerMatchers(MatchFinder *Finder) {
2020
Finder->addMatcher(
21-
cxxMethodDecl(ofClass(classTemplateSpecializationDecl(
21+
cxxMethodDecl(isVirtual(),
22+
ofClass(classTemplateSpecializationDecl(
2223
unless(isExplicitTemplateSpecialization()))
2324
.bind("specialization")),
24-
isVirtual(), unless(isUsed()),
25+
unless(isUsed()), unless(isPure()),
2526
unless(cxxDestructorDecl(isDefaulted())))
2627
.bind("method"),
2728
this);

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,11 @@ Changes in existing checks
121121

122122
- Improved :doc:`misc-header-include-cycle
123123
<clang-tidy/checks/misc/header-include-cycle>` check performance.
124-
124+
125+
- Improved :doc:`portability-template-virtual-member-function
126+
<clang-tidy/checks/portability/template-virtual-member-function>` check to
127+
avoid false positives on pure virtual member functions.
128+
125129
Removed checks
126130
^^^^^^^^^^^^^^
127131

clang-tools-extra/test/clang-tidy/checkers/portability/template-virtual-member-function.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,3 +171,20 @@ struct NoInstantiation<int, U>{
171171
};
172172
};
173173
} // namespace PartialSpecializationNoInstantiation
174+
175+
namespace PureVirtual {
176+
177+
template<typename T>
178+
struct Base {
179+
virtual void foo() = 0;
180+
};
181+
182+
struct Derived : public Base<int> {
183+
void foo() {}
184+
};
185+
186+
void test() {
187+
Derived{}.foo();
188+
}
189+
190+
}

0 commit comments

Comments
 (0)