Fixed #3869 (References to items in array result it 'Uninitialized variable' errors)
This commit is contained in:
parent
2b3e5abef8
commit
c5da030674
|
@ -390,10 +390,10 @@ private:
|
||||||
const Variable* var2 = symbolDatabase->getVariableFromVarId(tok.varId());
|
const Variable* var2 = symbolDatabase->getVariableFromVarId(tok.varId());
|
||||||
if (var2 && var2->nameToken() == &tok && !var2->isStatic() && !var2->isConst()) {
|
if (var2 && var2->nameToken() == &tok && !var2->isStatic() && !var2->isConst()) {
|
||||||
if (tok.linkAt(1)) { // array
|
if (tok.linkAt(1)) { // array
|
||||||
const Token* end = tok.next();
|
const Token* endtok = tok.next();
|
||||||
while (end->link())
|
while (endtok->link())
|
||||||
end = end->link()->next();
|
endtok = endtok->link()->next();
|
||||||
if (end->str() != ";")
|
if (endtok->str() != ";")
|
||||||
return &tok;
|
return &tok;
|
||||||
}
|
}
|
||||||
const Scope* parent = var2->scope()->nestedIn;
|
const Scope* parent = var2->scope()->nestedIn;
|
||||||
|
@ -1036,7 +1036,7 @@ void CheckUninitVar::check()
|
||||||
void CheckUninitVar::checkScope(const Scope* scope)
|
void CheckUninitVar::checkScope(const Scope* scope)
|
||||||
{
|
{
|
||||||
for (std::list<Variable>::const_iterator i = scope->varlist.begin(); i != scope->varlist.end(); ++i) {
|
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;
|
continue;
|
||||||
if (i->nameToken()->strAt(1) == "(")
|
if (i->nameToken()->strAt(1) == "(")
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -53,6 +53,7 @@ private:
|
||||||
// ExecutionPath functionality
|
// ExecutionPath functionality
|
||||||
TEST_CASE(uninitvar2);
|
TEST_CASE(uninitvar2);
|
||||||
TEST_CASE(uninitvar3); // #3844
|
TEST_CASE(uninitvar3); // #3844
|
||||||
|
TEST_CASE(uninitvar4); // #3869 (reference)
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkUninitVar(const char code[]) {
|
void checkUninitVar(const char code[]) {
|
||||||
|
@ -2149,6 +2150,17 @@ private:
|
||||||
" )\n"
|
" )\n"
|
||||||
"}\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)
|
REGISTER_TEST(TestUninitVar)
|
||||||
|
|
Loading…
Reference in New Issue