Add test cases for #7899, #7974, #9256 (#3726)

* Add test case for #7899 and #7974

* Add test case for ##9256
This commit is contained in:
chrchr-github 2022-01-20 16:15:38 +01:00 committed by GitHub
parent 4d44d0c079
commit 7f9ef8c321
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 0 deletions

View File

@ -3858,6 +3858,14 @@ private:
" return foo < bar;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
// #9256
check("bool f() {\n"
" bool b = false;\n"
" b = true;\n"
" return b;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void alwaysTrueSymbolic()

View File

@ -147,6 +147,7 @@ private:
TEST_CASE(duplicateExpression10); // #9485
TEST_CASE(duplicateExpression11); // #8916 (function call)
TEST_CASE(duplicateExpression12); // #10026
TEST_CASE(duplicateExpression13); // #7899
TEST_CASE(duplicateExpressionLoop);
TEST_CASE(duplicateValueTernary);
TEST_CASE(duplicateExpressionTernary); // #6391
@ -5451,6 +5452,13 @@ private:
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (style) Same expression on both sides of '-'.\n", errout.str());
}
void duplicateExpression13() { //#7899
check("void f() {\n"
" if (sizeof(long) == sizeof(long long)) {}\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void duplicateExpressionLoop() {
check("void f() {\n"
" int a = 1;\n"

View File

@ -53,6 +53,7 @@ private:
TEST_CASE(unusedMain);
TEST_CASE(initializationIsNotAFunction);
TEST_CASE(operator1); // #3195
TEST_CASE(operator2); // #7974
TEST_CASE(returnRef);
TEST_CASE(attribute); // #3471 - FP __attribute__(constructor)
TEST_CASE(initializer_list);
@ -327,6 +328,19 @@ private:
ASSERT_EQUALS("", errout.str());
}
void operator2() { // #7974
check("bool operator==(const data_t& a, const data_t& b) {\n"
" return (a.fd == b.fd);\n"
"}\n"
"bool operator==(const event& a, const event& b) {\n"
" return ((a.events == b.events) && (a.data == b.data));\n"
"}\n"
"int main(event a, event b) {\n"
" return a == b;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void returnRef() {
check("int& foo() {return x;}");
ASSERT_EQUALS("[test.cpp:1]: (style) The function 'foo' is never used.\n", errout.str());