From 7e1ddea653900e66b20222d6949911cff9eee35b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 2 Jul 2015 20:52:04 +0200 Subject: [PATCH] One more fix for #6811 (ValueFlow: result of ?:) --- lib/valueflow.cpp | 4 +--- test/testvalueflow.cpp | 6 ++++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 93e2b7872..9895465e6 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -355,10 +355,8 @@ static void setTokenValue(Token* tok, const ValueFlow::Value &value) ValueFlow::Value v(value); - if (!variables.empty()) { + if (!variables.empty()) v.varId = *(variables.begin()); - return; - } setTokenValue(parent, v); } diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index f2fac5226..9cbd51346 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -260,6 +260,12 @@ private: ASSERT_EQUALS(2, values.front().intvalue); ASSERT_EQUALS(3, values.back().intvalue); + code = "void f(int a) { x = a ? 2 : 3; }\n"; + values = tokenValues(code,"?"); + ASSERT_EQUALS(2U, values.size()); + ASSERT_EQUALS(2, values.front().intvalue); + ASSERT_EQUALS(3, values.back().intvalue); + // function call => calculation code = "void f(int x) {\n" " a = x + 8;\n"