Fixed #8835 (friend class and non-empty constructor: Uninitialized members not reported) (#1466)

This commit is contained in:
IOBYTE 2018-11-06 00:44:08 -05:00 committed by Daniel Marjamäki
parent 00340efc57
commit c966f31183
2 changed files with 35 additions and 1 deletions

View File

@ -764,7 +764,7 @@ void CheckClass::initializeVarList(const Function &func, std::list<const Functio
else {
assignAllVar(usage);
}
} else if (Token::Match(ftok, "::| %name% (") && ftok->str() != "if") {
} else if (Token::Match(ftok, "::| %name% (") && !Token::Match(ftok, "if|while|for")) {
if (ftok->str() == "::")
ftok = ftok->next();

View File

@ -145,6 +145,7 @@ private:
TEST_CASE(uninitVar29);
TEST_CASE(uninitVar30); // ticket #6417
TEST_CASE(uninitVar31); // ticket #8271
TEST_CASE(uninitVar32); // ticket #8835
TEST_CASE(uninitVarEnum1);
TEST_CASE(uninitVarEnum2); // ticket #8146
TEST_CASE(uninitVarStream);
@ -2426,6 +2427,39 @@ private:
ASSERT_EQUALS("", errout.str());
}
void uninitVar32() { // ticket #8835
check("class Foo {\n"
" friend class Bar;\n"
" int member;\n"
"public:\n"
" Foo()\n"
" {\n"
" if (1) {}\n"
" }\n"
"};\n");
ASSERT_EQUALS("[test.cpp:5]: (warning) Member variable 'Foo::member' is not initialized in the constructor.\n", errout.str());
check("class Foo {\n"
" friend class Bar;\n"
" int member;\n"
"public:\n"
" Foo()\n"
" {\n"
" while (1) {}\n"
" }\n"
"};\n");
ASSERT_EQUALS("[test.cpp:5]: (warning) Member variable 'Foo::member' is not initialized in the constructor.\n", errout.str());
check("class Foo {\n"
" friend class Bar;\n"
" int member;\n"
"public:\n"
" Foo()\n"
" {\n"
" for (;;) {}\n"
" }\n"
"};\n");
ASSERT_EQUALS("[test.cpp:5]: (warning) Member variable 'Foo::member' is not initialized in the constructor.\n", errout.str());
}
void uninitVarArray1() {
check("class John\n"
"{\n"