Skip to content

Commit 120c572

Browse files
committed
Fixed #9750 (Chained stream operation gives uninitvar error)
1 parent 8c2c81d commit 120c572

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

lib/astutils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1353,7 +1353,7 @@ bool isVariableChanged(const Token *tok, int indirect, const Settings *settings,
13531353
}
13541354
}
13551355

1356-
if (isLikelyStreamRead(cpp, tok->previous()))
1356+
if (cpp && Token::simpleMatch(tok2->astParent(), ">>") && tok2->astParent()->astOperand2() == tok2 && isLikelyStreamRead(cpp, tok2->astParent()))
13571357
return true;
13581358

13591359
if (isLikelyStream(cpp, tok2))

test/testuninitvar.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4242,14 +4242,26 @@ class TestUninitVar : public TestFixture {
42424242
"}");
42434243
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: a\n", errout.str());
42444244

4245-
valueFlowUninit("struct S { int x; };\n" // #9417
4246-
"void f() {\n"
4247-
" S s;\n"
4248-
" return s(1);\n"
4245+
// #9750
4246+
valueFlowUninit("struct S {\n"
4247+
" int one;\n"
4248+
" int two;\n"
4249+
"};\n"
4250+
"\n"
4251+
"void test(std::istringstream& in) {\n"
4252+
" S p;\n"
4253+
" in >> p.one >> p.two;\n"
42494254
"}");
42504255
ASSERT_EQUALS("", errout.str());
42514256
}
42524257

4258+
valueFlowUninit("struct S { int x; };\n" // #9417
4259+
"void f() {\n"
4260+
" S s;\n"
4261+
" return s(1);\n"
4262+
"}");
4263+
ASSERT_EQUALS("", errout.str());
4264+
42534265
valueFlowUninit("void a() {\n" // asm
42544266
" int x;\n"
42554267
" asm();\n"

0 commit comments

Comments
 (0)