Skip to content

Commit b456122

Browse files
Partial fix for #10358: set value for int s = int(4); (#3523)
1 parent 60fd53e commit b456122

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

test/testastutils.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,12 @@ class TestAstUtils : public TestFixture {
241241
inconclusive = false;
242242
ASSERT_EQUALS(false, isVariableChangedByFunctionCall(code, "x ) ;", &inconclusive));
243243
ASSERT_EQUALS(true, inconclusive);
244+
245+
code = "int f(int x) {\n"
246+
"return int(x);\n"
247+
"}\n";
248+
ASSERT_EQUALS(false, isVariableChangedByFunctionCall(code, "x ) ;", &inconclusive));
249+
TODO_ASSERT_EQUALS(false, true, inconclusive);
244250
}
245251

246252
bool nextAfterAstRightmostLeaf(const char code[], const char parentPattern[], const char rightPattern[]) {

test/testvalueflow.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4402,6 +4402,22 @@ class TestValueFlow : public TestFixture {
44024402
ASSERT(value.isKnown());
44034403
ASSERT_EQUALS(1, value.intvalue);
44044404

4405+
code = "bool f() {\n"
4406+
" const int s = int( 4 );"
4407+
" return s == 4;\n" // <- known value
4408+
"}";
4409+
value = valueOfTok(code, "==");
4410+
ASSERT(value.isKnown());
4411+
ASSERT_EQUALS(1, value.intvalue);
4412+
4413+
code = "bool f() {\n"
4414+
" const int s = int{ 4 };"
4415+
" return s == 4;\n" // <- known value
4416+
"}";
4417+
value = valueOfTok(code, "==");
4418+
ASSERT(value.isKnown());
4419+
ASSERT_EQUALS(1, value.intvalue);
4420+
44054421
// calculation with known result
44064422
code = "int f(int x) { a = x & 0; }"; // <- & is 0
44074423
value = valueOfTok(code, "&");

0 commit comments

Comments
 (0)