Fixed #9750 (Chained stream operation gives uninitvar error)

This commit is contained in:
Daniel Marjamäki 2020-06-06 15:24:01 +02:00
parent 8c2c81dbcd
commit 120c572252
2 changed files with 17 additions and 5 deletions

View File

@ -1353,7 +1353,7 @@ bool isVariableChanged(const Token *tok, int indirect, const Settings *settings,
}
}
if (isLikelyStreamRead(cpp, tok->previous()))
if (cpp && Token::simpleMatch(tok2->astParent(), ">>") && tok2->astParent()->astOperand2() == tok2 && isLikelyStreamRead(cpp, tok2->astParent()))
return true;
if (isLikelyStream(cpp, tok2))

View File

@ -4242,14 +4242,26 @@ private:
"}");
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: a\n", errout.str());
valueFlowUninit("struct S { int x; };\n" // #9417
"void f() {\n"
" S s;\n"
" return s(1);\n"
// #9750
valueFlowUninit("struct S {\n"
" int one;\n"
" int two;\n"
"};\n"
"\n"
"void test(std::istringstream& in) {\n"
" S p;\n"
" in >> p.one >> p.two;\n"
"}");
ASSERT_EQUALS("", errout.str());
}
valueFlowUninit("struct S { int x; };\n" // #9417
"void f() {\n"
" S s;\n"
" return s(1);\n"
"}");
ASSERT_EQUALS("", errout.str());
valueFlowUninit("void a() {\n" // asm
" int x;\n"
" asm();\n"