@@ -2203,13 +2203,35 @@ class TestUninitVar : public TestFixture {
22032203 " }\n " );
22042204 ASSERT_EQUALS (" " , errout_str ());
22052205
2206+ // #15005
22062207 checkUninitVar (" void f() {\n "
22072208 " char *p = new char;\n "
22082209 " p += 1;\n "
22092210 " delete (p - 1);\n "
22102211 " }\n " );
22112212 ASSERT_EQUALS (" " , errout_str ());
22122213
2214+ checkUninitVar (" void f() {\n "
2215+ " char *p = new char;\n "
2216+ " *p += 1;\n "
2217+ " delete p;\n "
2218+ " }\n " );
2219+ ASSERT_EQUALS (" [test.cpp:3:6]: (error) Memory is allocated but not initialized: p [uninitdata]\n " , errout_str ());
2220+
2221+ checkUninitVar (" void f() {\n "
2222+ " char *p = new char;\n "
2223+ " (*p)++;\n "
2224+ " delete p;\n "
2225+ " }\n " );
2226+ ASSERT_EQUALS (" [test.cpp:3:7]: (error) Memory is allocated but not initialized: p [uninitdata]\n " , errout_str ());
2227+
2228+ checkUninitVar (" void f() {\n "
2229+ " char *p = new char;\n "
2230+ " p[0]++;\n "
2231+ " delete p;\n "
2232+ " }\n " );
2233+ ASSERT_EQUALS (" [test.cpp:3:5]: (error) Memory is allocated but not initialized: p [uninitdata]\n " , errout_str ());
2234+
22132235 checkUninitVar (" void f() {\n "
22142236 " char *buf = (char *)malloc(1);\n "
22152237 " if (!buf)\n "
@@ -2226,7 +2248,7 @@ class TestUninitVar : public TestFixture {
22262248 " }\n " );
22272249 ASSERT_EQUALS (" " , errout_str ());
22282250
2229- checkUninitVar (" void g() {\n " // #15005
2251+ checkUninitVar (" void g() {\n "
22302252 " int* p = new int;\n "
22312253 " ++p;\n "
22322254 " delete (p - 1);\n "
@@ -8207,6 +8229,16 @@ class TestUninitVar : public TestFixture {
82078229 " }\n " );
82088230 ASSERT_EQUALS (" [test.cpp:6:4] -> [test.cpp:2:10]: (error) Using argument p that points at uninitialized variable x [ctuuninitvar]\n " , errout_str ());
82098231
8232+ ctu (" void f(int *p) {\n "
8233+ " a += *p;\n "
8234+ " }\n "
8235+ " int main() {\n "
8236+ " int x;\n "
8237+ " f(&x);\n "
8238+ " }\n " );
8239+ ASSERT_EQUALS (" [test.cpp:6:4] -> [test.cpp:2:11]: (error) Using argument p that points at uninitialized variable x [ctuuninitvar]\n " , errout_str ());
8240+
8241+
82108242 ctu (" void use(int *p) { a = *p + 3; }\n "
82118243 " void call(int x, int *p) { x++; use(p); }\n "
82128244 " int main() {\n "
0 commit comments