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()); } };