Fixed false positive #6717

This commit is contained in:
PKEuS 2015-07-21 11:46:41 +02:00
parent dd9cb929bf
commit bdd53b4142
2 changed files with 10 additions and 1 deletions

View File

@ -1965,7 +1965,7 @@ bool CheckUninitVar::isMemberVariableUsage(const Token *tok, bool isPointer, All
if (isMemberVariableAssignment(tok, membervar))
return false;
if (Token::Match(tok, "%name% . %name%") && tok->strAt(2) == membervar)
if (Token::Match(tok, "%name% . %name%") && tok->strAt(2) == membervar && !(tok->tokAt(-2)->variable() && tok->tokAt(-2)->variable()->isReference()))
return true;
else if (!isPointer && Token::Match(tok->previous(), "[(,] %name% [,)]") && isVariableUsage(tok, isPointer, alloc))
return true;

View File

@ -1705,6 +1705,15 @@ private:
" strchr(s.c_str(), ',');\n"
"}");
ASSERT_EQUALS("", errout.str());
// #6717
checkUninitVarB("void f() {\n"
" struct thing { int value; };\n"
" thing it;\n"
" int& referenced_int = it.value;\n"
" referenced_int = 123;\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void uninitvar_return() {