Skip to content

Commit 728531a

Browse files
Add test cases for ValueFlow issue with cast/switch (danmar#3527)
1 parent 87d1ba4 commit 728531a

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

test/testvalueflow.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2959,6 +2959,36 @@ class TestValueFlow : public TestFixture {
29592959
"}\n";
29602960
ASSERT_EQUALS(false, testValueOfX(code, 12U, 3));
29612961

2962+
code = "long long f(const long long& x, const long long& y) {\n"
2963+
" switch (s) {\n"
2964+
" case 0:\n"
2965+
" if (x >= 64)\n"
2966+
" return 0;\n"
2967+
" return (long long)y << (long long)x;\n"
2968+
" case 1:\n"
2969+
" if (x >= 64) {\n"
2970+
" }\n"
2971+
" }\n"
2972+
" return 0; \n"
2973+
"}\n";
2974+
ASSERT_EQUALS(true, testValueOfX(code, 6U, 63));
2975+
ASSERT_EQUALS(true, testValueOfXImpossible(code, 6U, 64));
2976+
2977+
code = "long long f(const long long& x, const long long& y) {\n"
2978+
" switch (s) {\n"
2979+
" case 0:\n"
2980+
" if (x >= 64)\n"
2981+
" return 0;\n"
2982+
" return long long(y) << long long(x);\n"
2983+
" case 1:\n"
2984+
" if (x >= 64) {\n"
2985+
" }\n"
2986+
" }\n"
2987+
" return 0; \n"
2988+
"}\n";
2989+
ASSERT_EQUALS(true, testValueOfX(code, 6U, 63));
2990+
TODO_ASSERT_EQUALS(true, false, testValueOfXImpossible(code, 6U, 64));
2991+
29622992
code = "int g(int x) { throw 0; }\n"
29632993
"void f(int x) {\n"
29642994
" if (x == 3)\n"

0 commit comments

Comments
 (0)