From d06f93aebf454c2f674aad7a8c31fbe515b6597b Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Mon, 6 Feb 2023 22:06:04 +0100 Subject: [PATCH] Fix #11458 nullPointer false positive (#4758) --- lib/symboldatabase.cpp | 10 +++++++--- test/testnullpointer.cpp | 12 ++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 6bac86bef..cea84e997 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -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) diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index 6f321f849..852ba3908 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -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"