diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 951636ae7..c715282a1 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -4662,6 +4662,8 @@ static void valueFlowAfterCondition(TokenList *tokenlist, ValueFlow::Value false_value; const Token *vartok = parseCompareInt(tok, true_value, false_value); if (vartok) { + if (vartok->hasKnownValue()) + return cond; if (vartok->str() == "=" && vartok->astOperand1() && vartok->astOperand2()) vartok = vartok->astOperand1(); cond.true_values.push_back(true_value); diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index f56e91340..897a28d1c 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -2633,6 +2633,16 @@ private: " }\n" "}\n"; ASSERT_EQUALS(true, testValueOfXKnown(code, 7U, 0)); + + code = "void f(std::vector v) {\n" + " if (v.size() == 3) {\n" + " if (v.size() == 1) {\n" + " int x = 1;\n" + " int a = x;\n" + " }\n" + " }\n" + "}\n"; + ASSERT_EQUALS(true, testValueOfXKnown(code, 5U, 1)); } void valueFlowAfterConditionSeveralNot() {