Skip to content

Commit 3322793

Browse files
committed
checkVirtualFunctionCallInConstructor; Check should be 'style' since there is no UB. Disabled the check temporarily, it should use CTU to determine if the class is a base class
1 parent e31b2f8 commit 3322793

3 files changed

Lines changed: 7 additions & 6 deletions

File tree

lib/checkclass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2440,7 +2440,7 @@ void CheckClass::virtualFunctionCallInConstructorError(
24402440
}
24412441
}
24422442

2443-
reportError(errorPath, Severity::warning, "virtualCallInConstructor",
2443+
reportError(errorPath, Severity::style, "virtualCallInConstructor",
24442444
"Virtual function '" + funcname + "' is called from " + scopeFunctionTypeName + " '" + constructorName + "' at line " + MathLib::toString(lineNumber) + ". Dynamic binding is not used.", CWE(0U), false);
24452445
}
24462446

lib/checkclass.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ class CPPCHECKLIB CheckClass : public Check {
7373
checkClass.virtualDestructor();
7474
checkClass.checkConst();
7575
checkClass.copyconstructors();
76-
checkClass.checkVirtualFunctionCallInConstructor();
76+
// FIXME: Only report warnings for inherited classes
77+
// checkClass.checkVirtualFunctionCallInConstructor();
7778
checkClass.checkDuplInheritedMembers();
7879
checkClass.checkExplicitConstructors();
7980
checkClass.checkCopyCtorAndEqOperator();

test/testclass.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6836,21 +6836,21 @@ class TestClass : public TestFixture {
68366836
"};\n"
68376837
"A::A()\n"
68386838
"{f();}\n");
6839-
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());
6839+
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:3]: (style) Virtual function 'f' is called from constructor 'A()' at line 7. Dynamic binding is not used.\n", errout.str());
68406840

68416841
checkVirtualFunctionCall("class A {\n"
68426842
" virtual int f();\n"
68436843
" A() {f();}\n"
68446844
"};\n"
68456845
"int A::f() { return 1; }\n");
6846-
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());
6846+
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2]: (style) Virtual function 'f' is called from constructor 'A()' at line 3. Dynamic binding is not used.\n", errout.str());
68476847

68486848
checkVirtualFunctionCall("class A : B {\n"
68496849
" int f() override;\n"
68506850
" A() {f();}\n"
68516851
"};\n"
68526852
"int A::f() { return 1; }\n");
6853-
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());
6853+
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2]: (style) Virtual function 'f' is called from constructor 'A()' at line 3. Dynamic binding is not used.\n", errout.str());
68546854

68556855
checkVirtualFunctionCall("class B {\n"
68566856
" virtual int f() = 0;\n"
@@ -6860,7 +6860,7 @@ class TestClass : public TestFixture {
68606860
" A() {f();}\n"
68616861
"};\n"
68626862
"int A::f() { return 1; }\n");
6863-
ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:5]: (warning) Virtual function 'f' is called from constructor 'A()' at line 6. Dynamic binding is not used.\n", errout.str());
6863+
ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:5]: (style) Virtual function 'f' is called from constructor 'A()' at line 6. Dynamic binding is not used.\n", errout.str());
68646864

68656865
checkVirtualFunctionCall("class A\n"
68666866
"{\n"

0 commit comments

Comments
 (0)