Skip to content

Commit 54e2726

Browse files
committed
Fixed cppcheck-opensource#8636 (Misleading verbose message if virtual method called from destructor)
1 parent fc5d8e5 commit 54e2726

2 files changed

Lines changed: 3 additions & 4 deletions

File tree

‎lib/checkclass.cpp‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2377,8 +2377,7 @@ void CheckClass::virtualFunctionCallInConstructorError(
23772377
}
23782378

23792379
reportError(errorPath, Severity::warning, "virtualCallInConstructor",
2380-
"Virtual function '" + funcname + "' is called from " + scopeFunctionTypeName + " '" + constructorName + "' at line " + MathLib::toString(lineNumber) + ".\n"
2381-
"Call of pure virtual function '" + funcname + "' in " + scopeFunctionTypeName + ". Dynamic binding is not used.", CWE(0U), false);
2380+
"Virtual function '" + funcname + "' is called from " + scopeFunctionTypeName + " '" + constructorName + "' at line " + MathLib::toString(lineNumber) + ". Dynamic binding is not used.", CWE(0U), false);
23822381
}
23832382

23842383
void CheckClass::pureVirtualFunctionCallInConstructorError(

‎test/testclass.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6533,14 +6533,14 @@ class TestClass : public TestFixture {
65336533
"};\n"
65346534
"A::A()\n"
65356535
"{f();}\n");
6536-
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:3]: (warning) Virtual function 'f' is called from constructor 'A()' at line 7.\n", errout.str());
6536+
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:3]: (warning) Virtual function 'f' is called from constructor 'A()' at line 7. Dynamic binding is not used.\n", errout.str());
65376537

65386538
checkVirtualFunctionCall("class A {\n"
65396539
" virtual int f();\n"
65406540
" A() {f();}\n"
65416541
"};\n"
65426542
"int A::f() { return 1; }\n");
6543-
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2]: (warning) Virtual function 'f' is called from constructor 'A()' at line 3.\n", errout.str());
6543+
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2]: (warning) Virtual function 'f' is called from constructor 'A()' at line 3. Dynamic binding is not used.\n", errout.str());
65446544

65456545
checkVirtualFunctionCall("class A\n"
65466546
"{\n"

0 commit comments

Comments
 (0)