From 9d51b4450b676264ddba49935fc4f58f429a291a Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 27 Jul 2021 22:26:19 +0200 Subject: [PATCH] Add test cases for tickets #9976 and #10371 (#3364) --- test/testcondition.cpp | 9 ++++++++- test/testother.cpp | 12 ++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/test/testcondition.cpp b/test/testcondition.cpp index e94f3d106..7bbfbfbd9 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -127,8 +127,8 @@ private: TEST_CASE(duplicateConditionalAssign); TEST_CASE(checkAssignmentInCondition); - TEST_CASE(compareOutOfTypeRange); + TEST_CASE(knownConditionCast); // #9976 } void check(const char code[], Settings *settings, const char* filename = "test.cpp") { @@ -4334,6 +4334,13 @@ private: " if (b == true) {}\n" "}", &settingsUnix64); ASSERT_EQUALS("", errout.str()); + } + + void knownConditionCast() { // #9976 + check("void f(int i) {\n" + " if (i < 0 || (unsigned)i > 5) {}\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } }; diff --git a/test/testother.cpp b/test/testother.cpp index b3dd0c317..54282c7e0 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -255,6 +255,8 @@ private: TEST_CASE(sameExpressionPointers); TEST_CASE(checkOverlappingWrite); + + TEST_CASE(constVariableArrayMember); // #10371 } void check(const char code[], const char *filename = nullptr, bool experimental = false, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) { @@ -9489,6 +9491,16 @@ private: "}"); ASSERT_EQUALS("[test.cpp:2]: (error) Overlapping read/write in strcpy() is undefined behavior\n", errout.str()); } + + void constVariableArrayMember() { // #10371 + check("class Foo {\n" + "public:\n" + " Foo();\n" + " int GetVal() const { return m_Arr[0]; }\n" + " int m_Arr[1];\n" + "};\n"); + ASSERT_EQUALS("", errout.str()); + } }; REGISTER_TEST(TestOther)