Uninitialized variables; Fixed false positive in range for loop
This commit is contained in:
parent
fcdc0088c7
commit
ca5fab8219
|
@ -1138,12 +1138,17 @@ const Token* CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer,
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
// LHS in range for loop:
|
||||
// range for loop
|
||||
if (Token::simpleMatch(valueExpr->astParent(), ":") &&
|
||||
astIsLhs(valueExpr) &&
|
||||
valueExpr->astParent()->astParent() &&
|
||||
Token::simpleMatch(valueExpr->astParent()->astParent()->previous(), "for ("))
|
||||
return nullptr;
|
||||
Token::simpleMatch(valueExpr->astParent()->astParent()->previous(), "for (")) {
|
||||
if (astIsLhs(valueExpr))
|
||||
return nullptr;
|
||||
// Taking value by reference?
|
||||
const Token *lhs = valueExpr->astParent()->astOperand1();
|
||||
if (lhs && lhs->variable() && lhs->variable()->nameToken() == lhs && lhs->variable()->isReference())
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Stream read/write
|
||||
// FIXME this code is a hack!!
|
||||
|
|
|
@ -4164,6 +4164,12 @@ private:
|
|||
" for (item: itemList) {}\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
checkUninitVar("void f() {\n"
|
||||
" int buf[10];\n"
|
||||
" for (int &i: buf) { i = 0; }\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void uninitvar_static() { // #8734
|
||||
|
|
Loading…
Reference in New Issue