Skip to content

Commit d06f93a

Browse files
Fix #11458 nullPointer false positive (#4758)
1 parent a666e31 commit d06f93a

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

lib/symboldatabase.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5470,10 +5470,14 @@ const Function* Scope::findFunction(const Token *tok, bool requireConst) const
54705470
if (fallback2Func)
54715471
return fallback2Func;
54725472

5473-
// remove pure virtual function
5474-
matches.erase(std::remove_if(matches.begin(), matches.end(), [](const Function* m) {
5473+
// remove pure virtual function if there is an overrider
5474+
auto itPure = std::find_if(matches.begin(), matches.end(), [](const Function* m) {
54755475
return m->isPure();
5476-
}), matches.end());
5476+
});
5477+
if (itPure != matches.end() && std::any_of(matches.begin(), matches.end(), [&](const Function* m) {
5478+
return m->isImplicitlyVirtual() && m != *itPure;
5479+
}))
5480+
matches.erase(itPure);
54775481

54785482
// Only one candidate left
54795483
if (matches.size() == 1)

test/testnullpointer.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ class TestNullPointer : public TestFixture {
141141
TEST_CASE(nullpointer95); // #11142
142142
TEST_CASE(nullpointer96); // #11416
143143
TEST_CASE(nullpointer97); // #11229
144+
TEST_CASE(nullpointer98); // #11458
144145
TEST_CASE(nullpointer_addressOf); // address of
145146
TEST_CASE(nullpointerSwitch); // #2626
146147
TEST_CASE(nullpointer_cast); // #4692
@@ -2796,6 +2797,17 @@ class TestNullPointer : public TestFixture {
27962797
ASSERT_EQUALS("", errout.str());
27972798
}
27982799

2800+
void nullpointer98() // #11458
2801+
{
2802+
check("struct S { double* d() const; };\n"
2803+
"struct T {\n"
2804+
" virtual void g(double* b, double* d) const = 0;\n"
2805+
" void g(S* b) const { g(b->d(), nullptr); }\n"
2806+
" void g(S* b, S* d) const { g(b->d(), d->d()); }\n"
2807+
"}\n");
2808+
ASSERT_EQUALS("", errout.str());
2809+
}
2810+
27992811
void nullpointer_addressOf() { // address of
28002812
check("void f() {\n"
28012813
" struct X *x = 0;\n"

0 commit comments

Comments
 (0)