From 2a0716449f040328360ff356a7845dc23f27e4b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 24 Mar 2014 06:15:51 +0100 Subject: [PATCH] Fixed #5498 (C++0x11 default values for class fields and missing constructor) --- lib/checkclass.cpp | 2 +- test/testconstructors.cpp | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index a7f1700ee..b5e2676e6 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -89,7 +89,7 @@ void CheckClass::constructors() // If there is a private variable, there should be a constructor.. std::list::const_iterator 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))) { noConstructorError(scope->classDef, scope->className, scope->classDef->str() == "struct"); break; diff --git a/test/testconstructors.cpp b/test/testconstructors.cpp index 130b25256..044e5d655 100644 --- a/test/testconstructors.cpp +++ b/test/testconstructors.cpp @@ -66,6 +66,7 @@ private: TEST_CASE(simple10); // ticket #4388 TEST_CASE(simple11); // ticket #4536 TEST_CASE(simple12); // ticket #4620 + TEST_CASE(simple13); // #5498 - no constructor, c++11 assignments TEST_CASE(initvar_with_this); // BUG 2190300 TEST_CASE(initvar_if); // BUG 2190290 @@ -393,6 +394,14 @@ private: 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() { check("struct Fred\n" "{\n"