Fixed #4567 (false negative: The class 'B' does not have a constructor.)

This commit is contained in:
Robert Reif 2013-02-08 06:55:45 +01:00 committed by Daniel Marjamäki
parent 463121be71
commit fe5de60f32
2 changed files with 11 additions and 1 deletions

View File

@ -66,7 +66,8 @@ void CheckClass::constructors()
// If there is a private variable, there should be a constructor..
std::list<Variable>::const_iterator var;
for (var = scope->varlist.begin(); var != scope->varlist.end(); ++var) {
if (var->isPrivate() && !var->isClass() && !var->isStatic()) {
if (var->isPrivate() && !var->isStatic() &&
(!var->isClass() || (var->type() && var->type()->needInitialization == Scope::True))) {
noConstructorError(scope->classDef, scope->className, scope->classDef->str() == "struct");
break;
}

View File

@ -60,6 +60,7 @@ private:
TEST_CASE(simple5); // ticket #2560
TEST_CASE(simple6); // ticket #4085 - uninstantiated template class
TEST_CASE(simple7); // ticket #4531
TEST_CASE(simple8);
TEST_CASE(initvar_with_this); // BUG 2190300
TEST_CASE(initvar_if); // BUG 2190290
@ -311,6 +312,14 @@ private:
ASSERT_EQUALS("", errout.str());
}
void simple8() {
check("struct Fred { int x; };\n"
"class Barney { Fred fred; };\n"
"class Wilma { struct Betty { int x; } betty; };\n");
ASSERT_EQUALS("[test.cpp:2]: (style) The class 'Barney' does not have a constructor.\n"
"[test.cpp:3]: (style) The class 'Wilma' does not have a constructor.\n", errout.str());
}
void initvar_with_this() {
check("struct Fred\n"
"{\n"