From 90a29d986b8d0d351b9c80bce2e7aaedb079154a Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Wed, 12 Sep 2018 10:30:18 -0500 Subject: [PATCH] Fix issue 8730: Dont follow variables with unknown symbols (#1374) --- lib/astutils.cpp | 2 ++ test/testother.cpp | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index ac3c508dc..7fd1ba3c3 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -228,6 +228,8 @@ static const Token * followVariableExpression(const Token * tok, bool cpp, const // Recognized as a variable but the declaration is unknown } else if (tok2->varId() > 0) { return tok; + } else if(tok2->tokType() == Token::eName && !Token::Match(tok2, "sizeof|decltype|typeof") && !tok2->function()) { + return tok; } } return varTok; diff --git a/test/testother.cpp b/test/testother.cpp index 6e6e4b552..350f5e8c9 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -4266,6 +4266,20 @@ private: "}\n"); ASSERT_EQUALS("", errout.str()); + check("void f(bool c) {\n" + " const bool b = a;\n" + " if(c) { a = false; } \n" + " if(b && !a) { }\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + + check("void f() {\n" + " bool x = a;\n" + " dostuff();\n" + " if (x && a) {}\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + check("void f() {\n" " const bool b = g();\n" " if (!b && g()) {}\n"