From ed050659a39e487a83a48c5bf8367d31eb1d8455 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 23 Nov 2021 23:07:15 +0100 Subject: [PATCH] Add test cases, todos for #9790, #10358, #10462 (#3564) * Add test cases, todos * Format * Remove dupes * Format --- test/testassert.cpp | 5 +++++ test/testvalueflow.cpp | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/test/testassert.cpp b/test/testassert.cpp index 759f89858..808144edc 100644 --- a/test/testassert.cpp +++ b/test/testassert.cpp @@ -234,6 +234,11 @@ private: " assert(sizeof(struct { int a[x++]; })==sizeof(int));\n" "}"); ASSERT_EQUALS("", errout.str()); + + check("void foo() {\n" // #9790 + " assert(kad_bucket_hash(&(kad_guid) { .bytes = { 0 } }, & (kad_guid){.bytes = { 0 }}) == -1);\n" + "}"); + ASSERT_EQUALS("", errout.str()); } }; diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index bfec5dfad..68e07372a 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -4444,6 +4444,22 @@ private: ASSERT(value.isKnown()); ASSERT_EQUALS(1, value.intvalue); + code = "bool f() {\n" + " const int s = int{};" + " return s == 0;\n" // <- known value + "}"; + value = valueOfTok(code, "=="); + TODO_ASSERT_EQUALS(true, false, value.isKnown()); + TODO_ASSERT_EQUALS(1, 0, value.intvalue); + + code = "bool f() {\n" + " const int s = int();" + " return s == 0;\n" // <- known value + "}"; + value = valueOfTok(code, "=="); + TODO_ASSERT_EQUALS(true, false, value.isKnown()); + TODO_ASSERT_EQUALS(1, 0, value.intvalue); + // calculation with known result code = "int f(int x) { a = x & 0; }"; // <- & is 0 value = valueOfTok(code, "&"); @@ -6075,6 +6091,13 @@ private: " diff = (buf-b);\n" "}\n"; valueOfTok(code, "diff"); + + code = "void foo() {\n" // #10462 + " std::tuple t4(5.2f, 3.1f, 2.4f, 9.1f), t5(4, 6, 9, 27);\n" + " t4 = t5;\n" + " ASSERT(!(t4 < t5) && t4 <= t5);\n" + "}"; + valueOfTok(code, "<="); } void valueFlowHang() {