From 26e36a1d6b8693c4c4e7aa20ea6211f241ff2131 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 18 Apr 2018 16:13:24 +0200 Subject: [PATCH] Fix FP uninitvar when stream bool operator is used --- lib/astutils.cpp | 7 +++++-- test/testuninitvar.cpp | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 84431b9f9..6c806d5b1 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -631,13 +631,16 @@ bool isLikelyStreamRead(bool cpp, const Token *op) if (!cpp) return false; - if (!Token::Match(op, "& %name% ;|&") && !Token::Match(op, ">> %name% ;|>>")) + if (!Token::Match(op, "&|>>") || !op->astOperand2()) + return false; + + if (!Token::Match(op->astOperand2(), "%name%|.|*|[") && op->str() != op->astOperand2()->str()) return false; const Token *parent = op; while (parent->astParent() && parent->astParent()->str() == op->str()) parent = parent->astParent(); - if (parent->astParent()) + if (parent->astParent() && !Token::Match(parent->astParent(), "%oror%|&&|(|,|!")) return false; if (!parent->astOperand1() || !parent->astOperand2()) return false; diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 905e3cd68..8cf87ad46 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -2196,7 +2196,7 @@ private: { const char code[] = "void f() {\n" " int x;\n" - " i >> x;\n" + " if (i >> x) { }\n" "}"; checkUninitVar(code, "test.cpp"); ASSERT_EQUALS("", errout.str());