From 30f04a5a9678e0f8806dbaf0d36d861a64176680 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 2 Sep 2017 21:53:51 +0200 Subject: [PATCH] Fixed #8195 (False positive uninitvar (regression) - valueflow misses variable initialization via istringstream >>) --- lib/astutils.cpp | 9 +++++++++ test/testvalueflow.cpp | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index bb923df57..2dfdf58cc 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -458,6 +458,15 @@ bool isVariableChanged(const Token *start, const Token *end, const unsigned int if (Token::Match(tok->previous(), "++|-- %name%")) return true; + if (Token::simpleMatch(tok->previous(), ">>")) { + const Token *shr = tok->previous(); + if (Token::simpleMatch(shr->astParent(), ">>")) + return true; + const Token *lhs = shr->astOperand1(); + if (!lhs->valueType() || !lhs->valueType()->isIntegral()) + return true; + } + const Token *ftok = tok; while (ftok && !Token::Match(ftok, "[({[]")) ftok = ftok->astParent(); diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 41f586cd5..7209c360a 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -2625,6 +2625,16 @@ private: " f(x=3), return x+3;\n" "}"; ASSERT_EQUALS(0U, tokenValues(code, "x +").size()); + + // #8195 + code = "void foo(std::istream &is) {\n" + " int x;\n" + " if (is >> x) {\n" + " a = x;\n" + " }\n" + "}"; + values = tokenValues(code, "x ; }"); + ASSERT_EQUALS(true, values.empty()); } };