Fix #11458 nullPointer false positive (#4758)

This commit is contained in:
chrchr-github 2023-02-06 22:06:04 +01:00 committed by GitHub
parent a666e31801
commit d06f93aebf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 3 deletions

View File

@ -5470,10 +5470,14 @@ const Function* Scope::findFunction(const Token *tok, bool requireConst) const
if (fallback2Func)
return fallback2Func;
// remove pure virtual function
matches.erase(std::remove_if(matches.begin(), matches.end(), [](const Function* m) {
// remove pure virtual function if there is an overrider
auto itPure = std::find_if(matches.begin(), matches.end(), [](const Function* m) {
return m->isPure();
}), matches.end());
});
if (itPure != matches.end() && std::any_of(matches.begin(), matches.end(), [&](const Function* m) {
return m->isImplicitlyVirtual() && m != *itPure;
}))
matches.erase(itPure);
// Only one candidate left
if (matches.size() == 1)

View File

@ -141,6 +141,7 @@ private:
TEST_CASE(nullpointer95); // #11142
TEST_CASE(nullpointer96); // #11416
TEST_CASE(nullpointer97); // #11229
TEST_CASE(nullpointer98); // #11458
TEST_CASE(nullpointer_addressOf); // address of
TEST_CASE(nullpointerSwitch); // #2626
TEST_CASE(nullpointer_cast); // #4692
@ -2796,6 +2797,17 @@ private:
ASSERT_EQUALS("", errout.str());
}
void nullpointer98() // #11458
{
check("struct S { double* d() const; };\n"
"struct T {\n"
" virtual void g(double* b, double* d) const = 0;\n"
" void g(S* b) const { g(b->d(), nullptr); }\n"
" void g(S* b, S* d) const { g(b->d(), d->d()); }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void nullpointer_addressOf() { // address of
check("void f() {\n"
" struct X *x = 0;\n"