From bde6698bcd8c7a2cf249d0a523fd46b3b8023864 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 27 Apr 2014 10:21:20 +0200 Subject: [PATCH] Fixed #5731 (False positive with opposite conditions) --- lib/checkother.cpp | 3 +++ test/testother.cpp | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 603af7786..ec841b0e2 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -3321,6 +3321,9 @@ void CheckOther::oppositeInnerCondition() nonlocal |= (var && (!var->isLocal() || var->isStatic())); // TODO: if var is pointer check what it points at nonlocal |= (var && var->isPointer()); + } else if (cond->isName()) { + // varid is 0. this is possibly a nonlocal variable.. + nonlocal |= (cond->astParent() && cond->astParent()->isConstOp()); } } diff --git a/test/testother.cpp b/test/testother.cpp index 150082844..692fabb23 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -392,6 +392,16 @@ private: " }\n" "}"); ASSERT_EQUALS("", errout.str()); + + // #5731 - fp when undeclared variable is used + check("void f() {\n" + " if (x == -1){\n" + " x = do_something();\n" + " if (x != -1) {}\n" + " }\n" + "}"); + ASSERT_EQUALS("", errout.str()); + } void emptyBrackets() {