Fix #10841 FN uninitMemberVar when member is being used in constructor (regression) (#3909)

This commit is contained in:
chrchr-github 2022-03-16 20:35:55 +01:00 committed by GitHub
parent fb89a2c742
commit e073860e62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View File

@ -778,7 +778,7 @@ void CheckClass::initializeVarList(const Function &func, std::list<const Functio
} }
// Calling member variable function? // Calling member variable function?
if (Token::Match(ftok->next(), "%var% . %name% (")) { if (Token::Match(ftok->next(), "%var% . %name% (") && !(ftok->next()->valueType() && ftok->next()->valueType()->pointer)) {
for (const Variable &var : scope->varlist) { for (const Variable &var : scope->varlist) {
if (var.declarationId() == ftok->next()->varId()) { if (var.declarationId() == ftok->next()->varId()) {
/** @todo false negative: we assume function changes variable state */ /** @todo false negative: we assume function changes variable state */

View File

@ -179,6 +179,7 @@ private:
TEST_CASE(uninitVar31); // ticket #8271 TEST_CASE(uninitVar31); // ticket #8271
TEST_CASE(uninitVar32); // ticket #8835 TEST_CASE(uninitVar32); // ticket #8835
TEST_CASE(uninitVar33); // ticket #10295 TEST_CASE(uninitVar33); // ticket #10295
TEST_CASE(uninitVar34); // ticket #10841
TEST_CASE(uninitVarEnum1); TEST_CASE(uninitVarEnum1);
TEST_CASE(uninitVarEnum2); // ticket #8146 TEST_CASE(uninitVarEnum2); // ticket #8146
TEST_CASE(uninitVarStream); TEST_CASE(uninitVarStream);
@ -2822,6 +2823,15 @@ private:
ASSERT_EQUALS("[test.cpp:8]: (warning) Member variable 'B::x' is not initialized in the constructor.\n", errout.str()); ASSERT_EQUALS("[test.cpp:8]: (warning) Member variable 'B::x' is not initialized in the constructor.\n", errout.str());
} }
void uninitVar34() { // ticket #10841
check("struct A { void f() {} };\n"
"struct B {\n"
" B() { a->f(); }\n"
" A* a;\n"
"};\n");
ASSERT_EQUALS("[test.cpp:3]: (warning) Member variable 'B::a' is not initialized in the constructor.\n", errout.str());
}
void uninitVarArray1() { void uninitVarArray1() {
check("class John\n" check("class John\n"
"{\n" "{\n"