Reviewed handling of >> in return statements in C files in UninitVar checking
This commit is contained in:
parent
f0f69ed818
commit
7f5950967e
|
@ -430,7 +430,7 @@ private:
|
||||||
// is there assignment or ternary operator in the return statement?
|
// is there assignment or ternary operator in the return statement?
|
||||||
bool assignment = false;
|
bool assignment = false;
|
||||||
for (const Token *tok2 = tok.next(); tok2 && tok2->str() != ";"; tok2 = tok2->next()) {
|
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;
|
assignment = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -222,12 +222,20 @@ private:
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
{
|
||||||
checkUninitVar("static int foo() {\n"
|
checkUninitVar("static int foo() {\n"
|
||||||
" int ret;\n"
|
" int ret;\n"
|
||||||
" return cin >> ret;\n"
|
" return cin >> ret;\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
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"
|
checkUninitVar("void f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" int a;\n"
|
" int a;\n"
|
||||||
|
|
Loading…
Reference in New Issue