fix false positive of virtual function call (#3553)

This commit is contained in:
nomick 2021-11-11 07:53:30 +01:00 committed by GitHub
parent 77069d810c
commit 5865b05703
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -2423,7 +2423,7 @@ void CheckClass::checkVirtualFunctionCallInConstructor()
continue;
if (callstack.back()->function()->isPure())
pureVirtualFunctionCallInConstructorError(scope->function, callstack, callstack.back()->str());
else
else if (!callstack.back()->function()->hasFinalSpecifier())
virtualFunctionCallInConstructorError(scope->function, callstack, callstack.back()->str());
}
}

View File

@ -6968,6 +6968,17 @@ private:
" A() { f(); }\n"
"};\n");
ASSERT_EQUALS("", errout.str());
checkVirtualFunctionCall("class B {\n"
"public:"
" virtual void f() {}\n"
"};\n"
"class A : B {\n"
"public:"
" void f() override final {}\n"
" A() { f(); }\n"
"};\n");
ASSERT_EQUALS("", errout.str());
}
void pureVirtualFunctionCall() {