Fixed #4567 (false negative: The class 'B' does not have a constructor.)
This commit is contained in:
parent
463121be71
commit
fe5de60f32
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue