Add regression test for #8780 (#1619)

Ticket #8780 was fixed in b839ad60dd.
Add a test to avoid regressions.
This commit is contained in:
rikardfalkeborn 2019-01-25 07:48:18 +01:00 committed by Daniel Marjamäki
parent 8f36b7d23b
commit a05079fef7
1 changed files with 16 additions and 0 deletions

View File

@ -73,6 +73,7 @@ private:
TEST_CASE(incorrectLogicOperator10); // enum
TEST_CASE(incorrectLogicOperator11);
TEST_CASE(incorrectLogicOperator12);
TEST_CASE(incorrectLogicOperator13);
TEST_CASE(secondAlwaysTrueFalseWhenFirstTrueError);
TEST_CASE(incorrectLogicOp_condSwapping);
TEST_CASE(testBug5895);
@ -1300,6 +1301,21 @@ private:
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3] -> [test.cpp:5]: (warning) Logical conjunction always evaluates to false: a > x && a < y.\n", errout.str());
}
void incorrectLogicOperator13() {
// 8780
check("void f(const int &v) {\n"
" const int x=v;\n"
" if ((v == 1) && (x == 2)) {;}\n"
"}\n");
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Logical conjunction always evaluates to false: v == 1 && x == 2.\n", errout.str());
check("void f2(const int *v) {\n"
" const int *x=v;\n"
" if ((*v == 1) && (*x == 2)) {;}\n"
"}\n");
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Logical conjunction always evaluates to false: *(v) == 1 && *(x) == 2.\n", errout.str());
}
void secondAlwaysTrueFalseWhenFirstTrueError() {
check("void f(int x) {\n"
" if (x > 5 && x != 1)\n"