Fixed #3196 (False positive: member variable not initialized in constructor (union))
This commit is contained in:
parent
add2b3706b
commit
1b1fd9d39c
|
@ -86,6 +86,22 @@ void CheckClass::constructors()
|
|||
}
|
||||
}
|
||||
|
||||
// #3196 => bailout if there are nested unions
|
||||
// TODO: handle union variables better
|
||||
{
|
||||
bool bailout = false;
|
||||
for (std::list<Scope *>::const_iterator it = scope->nestedList.begin(); it != scope->nestedList.end(); ++it) {
|
||||
const Scope * const nestedScope = *it;
|
||||
if (nestedScope->type == Scope::eUnion) {
|
||||
bailout = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (bailout)
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
std::list<Function>::const_iterator func;
|
||||
std::vector<Usage> usage(scope->varlist.size());
|
||||
|
||||
|
|
|
@ -80,6 +80,7 @@ private:
|
|||
TEST_CASE(uninitVarArray3D);
|
||||
TEST_CASE(uninitVarStruct1); // ticket #2172
|
||||
TEST_CASE(uninitVarStruct2); // ticket #838
|
||||
TEST_CASE(uninitVarUnion); // ticket #3196
|
||||
TEST_CASE(uninitMissingFuncDef); // can't expand function in constructor
|
||||
TEST_CASE(privateCtor1); // If constructor is private..
|
||||
TEST_CASE(privateCtor2); // If constructor is private..
|
||||
|
@ -2539,6 +2540,18 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void uninitVarUnion() { // ticket #3196
|
||||
checkUninitVar("class Fred\n"
|
||||
"{\n"
|
||||
"private:\n"
|
||||
" union { int a; int b; };\n"
|
||||
"public:\n"
|
||||
" Fred()\n"
|
||||
" { a = 0; }\n"
|
||||
"};\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void uninitMissingFuncDef() {
|
||||
// Unknown member function
|
||||
checkUninitVar("class Fred\n"
|
||||
|
|
|
@ -805,7 +805,7 @@ private:
|
|||
" {\n"
|
||||
" }\n"
|
||||
"};\n");
|
||||
ASSERT_EQUALS("[test.cpp:9]: (warning) Member variable 'Fred::U' is not initialized in the constructor.\n", errout.str());
|
||||
TODO_ASSERT_EQUALS("[test.cpp:9]: (warning) Member variable 'Fred::U' is not initialized in the constructor.\n", "", errout.str());
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue