From 405a1fba1105d24c25327370d1800ef207e9378d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 14 Jul 2015 18:02:26 +0200 Subject: [PATCH] ValueFlow: set values for false/true --- lib/valueflow.cpp | 7 +++++++ test/testvalueflow.cpp | 9 +++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index bfa0ed1bd..786020cfa 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -455,6 +455,13 @@ static void valueFlowNumber(TokenList *tokenlist) if (tok->isNumber() && MathLib::isInt(tok->str())) setTokenValue(tok, ValueFlow::Value(MathLib::toLongNumber(tok->str()))); } + + if (tokenlist->isCPP()) { + for (Token *tok = tokenlist->front(); tok; tok = tok->next()) { + if (tok->isName() && !tok->varId() && Token::Match(tok, "false|true")) + setTokenValue(tok, ValueFlow::Value(tok->str() == "true")); + } + } } static void valueFlowString(TokenList *tokenlist) diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index c42b3ce0f..64ad18202 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -151,12 +151,9 @@ private: } void valueFlowNumber() { - const char *code; - - code = "void f() {\n" - " x = 123;\n" - "}"; - ASSERT_EQUALS(123, valueOfTok(code, "123").intvalue); + ASSERT_EQUALS(123, valueOfTok("x=123;", "123").intvalue); + ASSERT_EQUALS(0, valueOfTok("x=false;", "false").intvalue); + ASSERT_EQUALS(1, valueOfTok("x=true;", "true").intvalue); } void valueFlowString() {