Fixed false positives in CheckUninitVar::checkStruct()
This commit is contained in:
parent
bd7765e008
commit
346532d312
|
@ -1126,7 +1126,10 @@ void CheckUninitVar::checkStruct(const Scope* scope, const Token *tok, const Var
|
|||
if (scope2->className == structname && scope2->numConstructors == 0U) {
|
||||
for (std::list<Variable>::const_iterator it = scope2->varlist.begin(); it != scope2->varlist.end(); ++it) {
|
||||
const Variable &var = *it;
|
||||
if (!var.hasDefault() && !var.isArray()) {
|
||||
|
||||
if (var.hasDefault() || var.isArray() || (!_tokenizer->isC() && var.isClass() && (!var.type() || var.type()->needInitialization != Type::True)))
|
||||
continue;
|
||||
|
||||
// is the variable declared in a inner union?
|
||||
bool innerunion = false;
|
||||
for (std::list<Scope>::const_iterator it2 = symbolDatabase->scopeList.begin(); it2 != symbolDatabase->scopeList.end(); ++it2) {
|
||||
|
@ -1151,7 +1154,6 @@ void CheckUninitVar::checkStruct(const Scope* scope, const Token *tok, const Var
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void conditionAlwaysTrueOrFalse(const Token *tok, const std::map<unsigned int, int> &variableValue, bool *alwaysTrue, bool *alwaysFalse)
|
||||
|
|
|
@ -3301,6 +3301,51 @@ private:
|
|||
" int b = ab.b;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized struct member: ab.b\n", errout.str());
|
||||
|
||||
// STL class member
|
||||
checkUninitVar2("struct A {\n"
|
||||
" std::map<int, int> m;\n"
|
||||
" int i;\n"
|
||||
"};\n"
|
||||
"void foo() {\n"
|
||||
" A a;\n"
|
||||
" x = a.m;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// Unknown type (C++)
|
||||
checkUninitVar2("struct A {\n"
|
||||
" C m;\n"
|
||||
" int i;\n"
|
||||
"};\n"
|
||||
"void foo() {\n"
|
||||
" A a;\n"
|
||||
" x = a.m;\n"
|
||||
"}", "test.cpp");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// Unknown type (C)
|
||||
checkUninitVar2("struct A {\n"
|
||||
" C m;\n"
|
||||
" int i;\n"
|
||||
"};\n"
|
||||
"void foo() {\n"
|
||||
" A a;\n"
|
||||
" x = a.m;\n"
|
||||
"}", "test.c");
|
||||
ASSERT_EQUALS("[test.c:7]: (error) Uninitialized struct member: a.m\n", errout.str());
|
||||
|
||||
// Type with constructor
|
||||
checkUninitVar2("class C { C(); }\n"
|
||||
"struct A {\n"
|
||||
" C m;\n"
|
||||
" int i;\n"
|
||||
"};\n"
|
||||
"void foo() {\n"
|
||||
" A a;\n"
|
||||
" x = a.m;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void uninitvar2_while() {
|
||||
|
|
Loading…
Reference in New Issue