Fixed #3869 (References to items in array result it 'Uninitialized variable' errors)

This commit is contained in:
Daniel Marjamäki 2012-06-08 16:17:55 +02:00
parent 2b3e5abef8
commit c5da030674
2 changed files with 17 additions and 5 deletions

View File

@ -390,10 +390,10 @@ private:
const Variable* var2 = symbolDatabase->getVariableFromVarId(tok.varId());
if (var2 && var2->nameToken() == &tok && !var2->isStatic() && !var2->isConst()) {
if (tok.linkAt(1)) { // array
const Token* end = tok.next();
while (end->link())
end = end->link()->next();
if (end->str() != ";")
const Token* endtok = tok.next();
while (endtok->link())
endtok = endtok->link()->next();
if (endtok->str() != ";")
return &tok;
}
const Scope* parent = var2->scope()->nestedIn;
@ -1036,7 +1036,7 @@ void CheckUninitVar::check()
void CheckUninitVar::checkScope(const Scope* scope)
{
for (std::list<Variable>::const_iterator i = scope->varlist.begin(); i != scope->varlist.end(); ++i) {
if ((i->type() && !i->isPointer()) || i->isStatic() || i->isConst() || i->isArray())
if ((i->type() && !i->isPointer()) || i->isStatic() || i->isConst() || i->isArray() || i->isReference())
continue;
if (i->nameToken()->strAt(1) == "(")
continue;

View File

@ -53,6 +53,7 @@ private:
// ExecutionPath functionality
TEST_CASE(uninitvar2);
TEST_CASE(uninitvar3); // #3844
TEST_CASE(uninitvar4); // #3869 (reference)
}
void checkUninitVar(const char code[]) {
@ -2149,6 +2150,17 @@ private:
" )\n"
"}\n");
}
// #3869 - reference variable
void uninitvar4() {
checkUninitVar2("void f() {\n"
" int buf[10];\n"
" int &x = buf[0];\n"
" buf[0] = 0;\n"
" x++;\n"
"}");
ASSERT_EQUALS("", errout.str());
}
};
REGISTER_TEST(TestUninitVar)