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
This commit is contained in:
parent
e31b2f8b73
commit
332279326f
|
@ -2440,7 +2440,7 @@ void CheckClass::virtualFunctionCallInConstructorError(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
reportError(errorPath, Severity::warning, "virtualCallInConstructor",
|
reportError(errorPath, Severity::style, "virtualCallInConstructor",
|
||||||
"Virtual function '" + funcname + "' is called from " + scopeFunctionTypeName + " '" + constructorName + "' at line " + MathLib::toString(lineNumber) + ". Dynamic binding is not used.", CWE(0U), false);
|
"Virtual function '" + funcname + "' is called from " + scopeFunctionTypeName + " '" + constructorName + "' at line " + MathLib::toString(lineNumber) + ". Dynamic binding is not used.", CWE(0U), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -73,7 +73,8 @@ public:
|
||||||
checkClass.virtualDestructor();
|
checkClass.virtualDestructor();
|
||||||
checkClass.checkConst();
|
checkClass.checkConst();
|
||||||
checkClass.copyconstructors();
|
checkClass.copyconstructors();
|
||||||
checkClass.checkVirtualFunctionCallInConstructor();
|
// FIXME: Only report warnings for inherited classes
|
||||||
|
// checkClass.checkVirtualFunctionCallInConstructor();
|
||||||
checkClass.checkDuplInheritedMembers();
|
checkClass.checkDuplInheritedMembers();
|
||||||
checkClass.checkExplicitConstructors();
|
checkClass.checkExplicitConstructors();
|
||||||
checkClass.checkCopyCtorAndEqOperator();
|
checkClass.checkCopyCtorAndEqOperator();
|
||||||
|
|
|
@ -6836,21 +6836,21 @@ private:
|
||||||
"};\n"
|
"};\n"
|
||||||
"A::A()\n"
|
"A::A()\n"
|
||||||
"{f();}\n");
|
"{f();}\n");
|
||||||
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());
|
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());
|
||||||
|
|
||||||
checkVirtualFunctionCall("class A {\n"
|
checkVirtualFunctionCall("class A {\n"
|
||||||
" virtual int f();\n"
|
" virtual int f();\n"
|
||||||
" A() {f();}\n"
|
" A() {f();}\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"int A::f() { return 1; }\n");
|
"int A::f() { return 1; }\n");
|
||||||
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());
|
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());
|
||||||
|
|
||||||
checkVirtualFunctionCall("class A : B {\n"
|
checkVirtualFunctionCall("class A : B {\n"
|
||||||
" int f() override;\n"
|
" int f() override;\n"
|
||||||
" A() {f();}\n"
|
" A() {f();}\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"int A::f() { return 1; }\n");
|
"int A::f() { return 1; }\n");
|
||||||
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());
|
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());
|
||||||
|
|
||||||
checkVirtualFunctionCall("class B {\n"
|
checkVirtualFunctionCall("class B {\n"
|
||||||
" virtual int f() = 0;\n"
|
" virtual int f() = 0;\n"
|
||||||
|
@ -6860,7 +6860,7 @@ private:
|
||||||
" A() {f();}\n"
|
" A() {f();}\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"int A::f() { return 1; }\n");
|
"int A::f() { return 1; }\n");
|
||||||
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());
|
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());
|
||||||
|
|
||||||
checkVirtualFunctionCall("class A\n"
|
checkVirtualFunctionCall("class A\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
|
Loading…
Reference in New Issue