Fixed #5498 (C++0x11 default values for class fields and missing constructor)

This commit is contained in:
Daniel Marjamäki 2014-03-24 06:15:51 +01:00
parent dbc8273cb7
commit 2a0716449f
2 changed files with 10 additions and 1 deletions

View File

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

View File

@ -66,6 +66,7 @@ private:
TEST_CASE(simple10); // ticket #4388 TEST_CASE(simple10); // ticket #4388
TEST_CASE(simple11); // ticket #4536 TEST_CASE(simple11); // ticket #4536
TEST_CASE(simple12); // ticket #4620 TEST_CASE(simple12); // ticket #4620
TEST_CASE(simple13); // #5498 - no constructor, c++11 assignments
TEST_CASE(initvar_with_this); // BUG 2190300 TEST_CASE(initvar_with_this); // BUG 2190300
TEST_CASE(initvar_if); // BUG 2190290 TEST_CASE(initvar_if); // BUG 2190290
@ -393,6 +394,14 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void simple13() { // #5498
check("class Fred {\n"
" int x=1;\n"
" int *y=0;\n"
"};\n");
ASSERT_EQUALS("", errout.str());
}
void initvar_with_this() { void initvar_with_this() {
check("struct Fred\n" check("struct Fred\n"
"{\n" "{\n"