You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: test/testcondition.cpp
+39Lines changed: 39 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -6546,6 +6546,45 @@ class TestCondition : public TestFixture {
6546
6546
"[test.cpp:4:13]: (style) Comparing expression of type 'const unsigned int &' against value 4294967295. Condition is always false. [compareValueOutOfTypeRangeError]\n",
6547
6547
errout_str());
6548
6548
6549
+
check("typedef unsigned int uint32;\n"
6550
+
"typedef unsigned long long uint64;\n"
6551
+
"typedef long long sint64;\n"
6552
+
"void f(uint32 x) {\n"
6553
+
" uint64 tmp = ((uint64)x) + 1ULL;\n"
6554
+
" if (tmp > 4294967295ULL)\n"
6555
+
" tmp = 4294967295ULL;\n"
6556
+
" if ((((sint64)((uint32)tmp)) - 1LL) < 0LL) {}\n"
6557
+
" if ((((sint64)((uint32)tmp)) - 1LL) > 4294967295LL) {}\n"
6558
+
"}\n", settingsUnix64);
6559
+
ASSERT_EQUALS("[test.cpp:9:43]: (style) Comparing expression of type 'signed long long' against value 4294967295. Condition is always false. [compareValueOutOfTypeRangeError]\n",
6560
+
errout_str());
6561
+
6562
+
// cast directly around variable: both the range-based and the declared-type
6563
+
// analysis can prove the condition invariant; diag() must prevent duplicates
6564
+
check("void f(unsigned char c) {\n"
6565
+
" if ((unsigned char)c > 255) {}\n"
6566
+
"}\n", settingsUnix64);
6567
+
ASSERT_EQUALS("[test.cpp:2:28]: (style) Comparing expression of type 'unsigned char' against value 255. Condition is always false. [compareValueOutOfTypeRangeError]\n",
6568
+
errout_str());
6569
+
6570
+
check("void f(unsigned char c) {\n"
6571
+
" if ((unsigned char)c == 256) {}\n"
6572
+
"}\n", settingsUnix64);
6573
+
ASSERT_EQUALS("[test.cpp:2:29]: (style) Comparing expression of type 'unsigned char' against value 256. Condition is always false. [compareValueOutOfTypeRangeError]\n",
6574
+
errout_str());
6575
+
6576
+
check("void f(unsigned int u) {\n"
6577
+
" if ((unsigned int)u > 4294967295ULL) {}\n"
6578
+
"}\n", settingsUnix64);
6579
+
ASSERT_EQUALS("[test.cpp:2:27]: (style) Comparing expression of type 'unsigned int' against value 4294967295. Condition is always false. [compareValueOutOfTypeRangeError]\n",
6580
+
errout_str());
6581
+
6582
+
check("void f(unsigned short s) {\n"
6583
+
" if ((unsigned int)s > 4294967295ULL) {}\n"
6584
+
"}\n", settingsUnix64);
6585
+
ASSERT_EQUALS("[test.cpp:2:27]: (style) Comparing expression of type 'unsigned int' against value 4294967295. Condition is always false. [compareValueOutOfTypeRangeError]\n",
0 commit comments