Reviewed handling of >> in return statements in C files in UninitVar checking

This commit is contained in:
Daniel Marjamäki 2012-06-23 15:47:48 +02:00
parent f0f69ed818
commit 7f5950967e
2 changed files with 14 additions and 6 deletions

View File

@ -430,7 +430,7 @@ private:
// is there assignment or ternary operator in the return statement?
bool assignment = false;
for (const Token *tok2 = tok.next(); tok2 && tok2->str() != ";"; tok2 = tok2->next()) {
if (tok2->str() == "=" || tok2->str() == ">>" || tok2->str() == "?" || Token::Match(tok2, "(|, &")) {
if (tok2->str() == "=" || (!isC && tok2->str() == ">>") || tok2->str() == "?" || Token::Match(tok2, "(|, &")) {
assignment = true;
break;
}

View File

@ -222,11 +222,19 @@ private:
"}\n");
ASSERT_EQUALS("", errout.str());
checkUninitVar("static int foo() {\n"
" int ret;\n"
" return cin >> ret;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
{
checkUninitVar("static int foo() {\n"
" int ret;\n"
" return cin >> ret;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
checkUninitVar("static int foo() {\n"
" int ret;\n"
" return cin >> ret;\n"
"}\n", "test.c");
ASSERT_EQUALS("[test.c:3]: (error) Uninitialized variable: ret\n", errout.str());
}
checkUninitVar("void f()\n"
"{\n"