From b4561229cb04620c11a0c5d92bbc9d9baeef5299 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Mon, 8 Nov 2021 20:28:55 +0100 Subject: [PATCH] Partial fix for #10358: set value for int s = int(4); (#3523) --- test/testastutils.cpp | 6 ++++++ test/testvalueflow.cpp | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/test/testastutils.cpp b/test/testastutils.cpp index 5bb57fb2f..27cba353c 100644 --- a/test/testastutils.cpp +++ b/test/testastutils.cpp @@ -241,6 +241,12 @@ private: inconclusive = false; ASSERT_EQUALS(false, isVariableChangedByFunctionCall(code, "x ) ;", &inconclusive)); ASSERT_EQUALS(true, inconclusive); + + code = "int f(int x) {\n" + "return int(x);\n" + "}\n"; + ASSERT_EQUALS(false, isVariableChangedByFunctionCall(code, "x ) ;", &inconclusive)); + TODO_ASSERT_EQUALS(false, true, inconclusive); } bool nextAfterAstRightmostLeaf(const char code[], const char parentPattern[], const char rightPattern[]) { diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 15aeec1db..8e55e3a02 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -4402,6 +4402,22 @@ private: ASSERT(value.isKnown()); ASSERT_EQUALS(1, value.intvalue); + code = "bool f() {\n" + " const int s = int( 4 );" + " return s == 4;\n" // <- known value + "}"; + value = valueOfTok(code, "=="); + ASSERT(value.isKnown()); + ASSERT_EQUALS(1, value.intvalue); + + code = "bool f() {\n" + " const int s = int{ 4 };" + " return s == 4;\n" // <- known value + "}"; + value = valueOfTok(code, "=="); + ASSERT(value.isKnown()); + ASSERT_EQUALS(1, value.intvalue); + // calculation with known result code = "int f(int x) { a = x & 0; }"; // <- & is 0 value = valueOfTok(code, "&");