File tree Expand file tree Collapse file tree 2 files changed +11
-1
lines changed
Expand file tree Collapse file tree 2 files changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -66,7 +66,8 @@ void CheckClass::constructors()
6666 // If there is a private variable, there should be a constructor..
6767 std::list<Variable>::const_iterator var;
6868 for (var = scope->varlist .begin (); var != scope->varlist .end (); ++var) {
69- if (var->isPrivate () && !var->isClass () && !var->isStatic ()) {
69+ if (var->isPrivate () && !var->isStatic () &&
70+ (!var->isClass () || (var->type () && var->type ()->needInitialization == Scope::True))) {
7071 noConstructorError (scope->classDef , scope->className , scope->classDef ->str () == " struct" );
7172 break ;
7273 }
Original file line number Diff line number Diff line change @@ -60,6 +60,7 @@ class TestConstructors : public TestFixture {
6060 TEST_CASE (simple5); // ticket #2560
6161 TEST_CASE (simple6); // ticket #4085 - uninstantiated template class
6262 TEST_CASE (simple7); // ticket #4531
63+ TEST_CASE (simple8);
6364
6465 TEST_CASE (initvar_with_this); // BUG 2190300
6566 TEST_CASE (initvar_if); // BUG 2190290
@@ -311,6 +312,14 @@ class TestConstructors : public TestFixture {
311312 ASSERT_EQUALS (" " , errout.str ());
312313 }
313314
315+ void simple8 () {
316+ check (" struct Fred { int x; };\n "
317+ " class Barney { Fred fred; };\n "
318+ " class Wilma { struct Betty { int x; } betty; };\n " );
319+ ASSERT_EQUALS (" [test.cpp:2]: (style) The class 'Barney' does not have a constructor.\n "
320+ " [test.cpp:3]: (style) The class 'Wilma' does not have a constructor.\n " , errout.str ());
321+ }
322+
314323 void initvar_with_this () {
315324 check (" struct Fred\n "
316325 " {\n "
You can’t perform that action at this time.
0 commit comments