diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 319300cc3..96a9232ef 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -2213,7 +2213,7 @@ bool isLikelyStreamRead(bool cpp, const Token *op) const Token *parent = op; while (parent->astParent() && parent->astParent()->str() == op->str()) parent = parent->astParent(); - if (parent->astParent() && !Token::Match(parent->astParent(), "%oror%|&&|(|,|.|!")) + if (parent->astParent() && !Token::Match(parent->astParent(), "%oror%|&&|(|,|.|!|;")) return false; if (op->str() == "&" && parent->astParent()) return false; diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index a9ee79dab..308860666 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -71,6 +71,7 @@ private: TEST_CASE(uninitvar9); // ticket #6424 TEST_CASE(uninitvar10); // ticket #9467 TEST_CASE(uninitvar11); // ticket #9123 + TEST_CASE(uninitvar12); // #10218 - stream read TEST_CASE(uninitvar_unconditionalTry); TEST_CASE(uninitvar_funcptr); // #6404 TEST_CASE(uninitvar_operator); // #6680 @@ -2773,6 +2774,15 @@ private: ASSERT_EQUALS("", errout.str()); } + void uninitvar12() { // 10218 + const char code[] = "void fp() {\n" + " std::stringstream ss;\n" + " for (int i; ss >> i;) {}\n" + "}"; + checkUninitVar(code); + ASSERT_EQUALS("", errout.str()); + } + void uninitvar_unconditionalTry() { // Unconditional scopes and try{} scopes checkUninitVar("int f() {\n"