Add test cases for tickets #9976 and #10371 (#3364)

This commit is contained in:
chrchr-github 2021-07-27 22:26:19 +02:00 committed by GitHub
parent 38d45c1b9c
commit 9d51b4450b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 1 deletions

View File

@ -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") {
@ -4335,6 +4335,13 @@ private:
"}", &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());
}
};
REGISTER_TEST(TestCondition)

View File

@ -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)