* Add tests for #6870, #10749

* Add test for #6372

* Add tests for #6855, #6857

* Add test for #6323

* Comment
This commit is contained in:
chrchr-github 2022-05-10 18:25:01 +02:00 committed by GitHub
parent 57e35513b9
commit ad547af6f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 0 deletions

View File

@ -4127,6 +4127,32 @@ private:
" int method() override { return 1; }\n"
"};\n");
ASSERT_EQUALS("", errout.str());
// #6855
check("struct S { int i; };\n"
"void f(S& s) {\n"
" if (!(s.i > 0) && (s.i != 0))\n"
" s.i = 0;\n"
" else if (s.i < 0)\n"
" s.s = 0;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (style) Condition 's.i<0' is always false\n", errout.str());
// #6857
check("int bar(int i) { return i; }\n"
"void foo() {\n"
" if (bar(1) == 0 && bar(1) > 0) {}\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3]: (style) Condition 'bar(1)==0' is always false\n"
"[test.cpp:3]: (style) Condition 'bar(1)>0' is always true\n",
errout.str());
check("struct S { int bar(int i) const; };\n"
"void foo(const S& s) {\n"
" if (s.bar(1) == 0 && s.bar(1) > 0) {}\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3]: (warning) Logical conjunction always evaluates to false: s.bar(1) == 0 && s.bar(1) > 0.\n",
errout.str());
}
void alwaysTrueSymbolic()

View File

@ -6384,6 +6384,14 @@ private:
" ((*&(*&s.t[0].p))) = 0;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
valueFlowUninit("struct S { int i; };\n" // #6323
"void f() {\n"
" struct S s;\n"
" int x = -3;\n"
" int y = x < (1, s.i);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: s.i\n", errout.str());
}
void ctu_(const char* file, int line, const char code[]) {