From 653a1ea83ed7655e0eb27be2557f9686ba375d03 Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Sat, 11 Jun 2022 04:00:40 -0500 Subject: [PATCH] Fix 11100: FP knownConditionTrueFalse with getter/setter member functions (#4198) * Fix 11100: FP knownConditionTrueFalse with getter/setter member functions * Format --- lib/valueflow.cpp | 4 +++- test/testcondition.cpp | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index ac85384ad..681521d6c 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -2926,8 +2926,10 @@ struct ExpressionAnalyzer : SingleValueFlowAnalyzer { assert(e && e->exprId() != 0 && "Not a valid expression"); dependOnThis = exprDependsOnThis(expr); setupExprVarIds(expr); - if (val.isSymbolicValue()) + if (val.isSymbolicValue()) { + dependOnThis |= exprDependsOnThis(val.tokvalue); setupExprVarIds(val.tokvalue); + } } static bool nonLocal(const Variable* var, bool deref) { diff --git a/test/testcondition.cpp b/test/testcondition.cpp index de2727299..71305295b 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -4483,6 +4483,20 @@ private: "}"); ASSERT_EQUALS("", errout.str()); + // #11100 + check("struct T {\n" + " bool m{};\n" + " void f(bool b);\n" + " bool get() const { return m; }\n" + " void set(bool v) { m = v; }\n" + "};\n" + "void T::f(bool b) {\n" + " bool tmp = get();\n" + " set(b);\n" + " if (tmp != get()) {}\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + // #9541 check("int f(int pos, int a) {\n" " if (pos <= 0)\n"