Fixed #4383 (Improve check: uninitialized member variable not detected when initialization is not proper)
This commit is contained in:
parent
2050cd71db
commit
80848c6e0e
|
@ -364,9 +364,10 @@ void CheckClass::initializeVarList(const Function &func, std::list<std::string>
|
|||
// Class constructor.. initializing variables like this
|
||||
// clKalle::clKalle() : var(value) { }
|
||||
if (initList) {
|
||||
if (level == 0 && Token::Match(ftok, "%var% ("))
|
||||
if (level == 0 && Token::Match(ftok, "%var% (")) {
|
||||
if (ftok->strAt(2) != ")")
|
||||
initVar(ftok->str(), scope, usage);
|
||||
else if (level != 0 && Token::Match(ftok, "%var% =")) // assignment in the initializer: var(value = x)
|
||||
} else if (level != 0 && Token::Match(ftok, "%var% =")) // assignment in the initializer: var(value = x)
|
||||
assignVar(ftok->str(), scope, usage);
|
||||
|
||||
else if (ftok->str() == "(")
|
||||
|
|
|
@ -109,6 +109,7 @@ private:
|
|||
TEST_CASE(uninitVar22); // ticket #3043
|
||||
TEST_CASE(uninitVar23); // ticket #3702
|
||||
TEST_CASE(uninitVar24); // ticket #3190
|
||||
TEST_CASE(uninitVar25); // ticket #4383
|
||||
TEST_CASE(uninitVarEnum);
|
||||
TEST_CASE(uninitVarStream);
|
||||
TEST_CASE(uninitVarTypedef);
|
||||
|
@ -1616,6 +1617,16 @@ private:
|
|||
"[test.cpp:12]: (warning) Member variable 'Sub::b' is not initialized in the constructor.\n", errout.str());
|
||||
}
|
||||
|
||||
void uninitVar25() { // ticket #4383
|
||||
check("class Fred {\n"
|
||||
" bool b;\n"
|
||||
"public:\n"
|
||||
" Fred() : b() { }\n"
|
||||
"};\n");
|
||||
|
||||
ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable 'Fred::b' is not initialized in the constructor.\n" , errout.str());
|
||||
}
|
||||
|
||||
void uninitVarArray1() {
|
||||
check("class John\n"
|
||||
"{\n"
|
||||
|
|
Loading…
Reference in New Issue