#6952: uninitvar - Added regression test cases

This commit is contained in:
orbitcowboy 2021-05-20 09:14:17 +02:00
parent 3af3d7fc06
commit ef757e5cf9
1 changed files with 28 additions and 0 deletions

View File

@ -1331,6 +1331,34 @@ private:
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
// #6952 - do-while-loop
checkUninitVar("void f(void)\n"
"{\n"
" int* p;\n"
" do\n"
" {\n"
" if (true) {;}\n"
" else\n"
" {\n"
" return 1;\n"
" }\n"
" *p = 7;\n" // <<
" p = new int(9);\n"
" } while (*p != 8);\n"
"}");
ASSERT_EQUALS("[test.cpp:11]: (error) Uninitialized variable: p\n", errout.str());
// #6952 - while-loop
checkUninitVar("void f(void)\n"
"{\n"
" int* p;\n"
" while (*p != 8) {\n" // <<
" *p = 7;\n"
" p = new int(9);\n"
" }\n"
"}");
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: p\n", errout.str());
// switch in loop // switch in loop
checkUninitVar("int foo(int *p) {\n" checkUninitVar("int foo(int *p) {\n"
" int x;\n" " int x;\n"