@@ -106,6 +106,7 @@ class TestUninitVar : public TestFixture {
106106 TEST_CASE (isVariableUsageDerefValueflow); // *p
107107
108108 TEST_CASE (uninitvar_memberaccess); // (&(a))->b <=> a.b
109+ TEST_CASE (uninitvar_diag);
109110
110111 // whole program analysis
111112 TEST_CASE (ctuTest);
@@ -132,6 +133,17 @@ class TestUninitVar : public TestFixture {
132133 checkuninitvar.check ();
133134 }
134135
136+ #define checkUninitVarAll (...) checkUninitVarAll_(__FILE__, __LINE__, __VA_ARGS__)
137+ template <size_t size>
138+ void checkUninitVarAll_ (const char * file, int line, const char (&code)[size]) {
139+ SimpleTokenizer tokenizer (settings, *this , true );
140+ ASSERT_LOC (tokenizer.tokenize (code), file, line);
141+
142+ CheckUninitVarImpl checkuninitvar (&tokenizer, settings, *this );
143+ checkuninitvar.valueFlowUninit ();
144+ checkuninitvar.check ();
145+ }
146+
135147 // TODO: get rid of this
136148 void checkUninitVar_ (const char * file, int line, const std::string& code) {
137149 SimpleTokenizer tokenizer (settings, *this );
@@ -8257,6 +8269,15 @@ class TestUninitVar : public TestFixture {
82578269 ASSERT_EQUALS (" " , errout_str ());
82588270 }
82598271
8272+ void uninitvar_diag () {
8273+ checkUninitVarAll (" struct S { int x; };\n " // #15216
8274+ " int f() {\n "
8275+ " S s;\n "
8276+ " return s.x;\n "
8277+ " }\n " );
8278+ ASSERT_EQUALS (" [test.cpp:4:14]: (error) Uninitialized variable: s.x [uninitvar]\n " , errout_str ());
8279+ }
8280+
82608281 void ctuTest () {
82618282 ctu (" void f(int *p) {\n "
82628283 " a = *p;\n "
0 commit comments