Fix crash with defaulted destructor (#3975)

This commit is contained in:
chrchr-github 2022-04-05 23:18:08 +02:00 committed by GitHub
parent c4dcfef385
commit f5313dc519
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -2540,7 +2540,7 @@ const std::list<const Token *> & CheckClass::getVirtualFunctionCalls(const Funct
virtualFunctionCallsMap[&function] = std::list<const Token *>(); virtualFunctionCallsMap[&function] = std::list<const Token *>();
std::list<const Token *> & virtualFunctionCalls = virtualFunctionCallsMap.find(&function)->second; std::list<const Token *> & virtualFunctionCalls = virtualFunctionCallsMap.find(&function)->second;
if (!function.hasBody()) if (!function.hasBody() || !function.functionScope)
return virtualFunctionCalls; return virtualFunctionCalls;
for (const Token *tok = function.arg->link(); tok != function.functionScope->bodyEnd; tok = tok->next()) { for (const Token *tok = function.arg->link(); tok != function.functionScope->bodyEnd; tok = tok->next()) {

View File

@ -7335,6 +7335,17 @@ private:
" virtual void f() {}\n" " virtual void f() {}\n"
"};\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()); 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() { void pureVirtualFunctionCall() {