Skip to content

Commit 5865b05

Browse files
authored
fix false positive of virtual function call (danmar#3553)
1 parent 77069d8 commit 5865b05

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/checkclass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2423,7 +2423,7 @@ void CheckClass::checkVirtualFunctionCallInConstructor()
24232423
continue;
24242424
if (callstack.back()->function()->isPure())
24252425
pureVirtualFunctionCallInConstructorError(scope->function, callstack, callstack.back()->str());
2426-
else
2426+
else if (!callstack.back()->function()->hasFinalSpecifier())
24272427
virtualFunctionCallInConstructorError(scope->function, callstack, callstack.back()->str());
24282428
}
24292429
}

test/testclass.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6968,6 +6968,17 @@ class TestClass : public TestFixture {
69686968
" A() { f(); }\n"
69696969
"};\n");
69706970
ASSERT_EQUALS("", errout.str());
6971+
6972+
checkVirtualFunctionCall("class B {\n"
6973+
"public:"
6974+
" virtual void f() {}\n"
6975+
"};\n"
6976+
"class A : B {\n"
6977+
"public:"
6978+
" void f() override final {}\n"
6979+
" A() { f(); }\n"
6980+
"};\n");
6981+
ASSERT_EQUALS("", errout.str());
69716982
}
69726983

69736984
void pureVirtualFunctionCall() {

0 commit comments

Comments
 (0)