File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -170,7 +170,7 @@ void CheckClass::constructors()
170170 if (var.isPrivate () && !var.isStatic () &&
171171 (!var.isClass () || (var.type () && var.type ()->needInitialization == Type::NeedInitialization::True))) {
172172 ++needInit;
173- if (!var.isInit () && !var.hasDefault ())
173+ if (!var.isInit () && !var.hasDefault () && var. nameToken ()-> scope () == scope) // don't warn for anonymous union members
174174 uninitVars.emplace_back (&var);
175175 else
176176 ++haveInit;
Original file line number Diff line number Diff line change @@ -3187,8 +3187,8 @@ class TestConstructors : public TestFixture {
31873187 ASSERT_EQUALS (" " , errout.str ());
31883188 }
31893189
3190- void uninitVarUnion1 () { // ticket #3196
3191- check (" class Fred\n "
3190+ void uninitVarUnion1 () {
3191+ check (" class Fred\n " // ticket #3196
31923192 " {\n "
31933193 " private:\n "
31943194 " union { int a; int b; };\n "
@@ -3197,6 +3197,12 @@ class TestConstructors : public TestFixture {
31973197 " { a = 0; }\n "
31983198 " };" );
31993199 ASSERT_EQUALS (" " , errout.str ());
3200+
3201+ check (" class Fred {\n "
3202+ " private:\n "
3203+ " union { int a{}; int b; };\n "
3204+ " };" );
3205+ ASSERT_EQUALS (" " , errout.str ());
32003206 }
32013207
32023208 void uninitVarUnion2 () {
You can’t perform that action at this time.
0 commit comments