diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 6d5a6e635..b1c45a5db 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -2540,7 +2540,7 @@ const std::list & CheckClass::getVirtualFunctionCalls(const Funct virtualFunctionCallsMap[&function] = std::list(); std::list & virtualFunctionCalls = virtualFunctionCallsMap.find(&function)->second; - if (!function.hasBody()) + if (!function.hasBody() || !function.functionScope) return virtualFunctionCalls; for (const Token *tok = function.arg->link(); tok != function.functionScope->bodyEnd; tok = tok->next()) { diff --git a/test/testclass.cpp b/test/testclass.cpp index 1ce57288d..48ebb8e02 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -7335,6 +7335,17 @@ private: " virtual void f() {}\n" "};\n"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) Virtual function 'f' is called from constructor 'B()' at line 2. Dynamic binding is not used.\n", errout.str()); + + checkVirtualFunctionCall("class S {\n" // don't crash + " ~S();\n" + "public:\n" + " S();\n" + "};\n" + "S::S() {\n" + " typeid(S);\n" + "}\n" + "S::~S() = default;\n"); + ASSERT_EQUALS("", errout.str()); } void pureVirtualFunctionCall() {