diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index c1f5e9fd7..c2879a6a9 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -161,7 +161,7 @@ void CheckClass::constructors() if (usage[count].assign || usage[count].init || var.isStatic()) continue; - if (var.valueType()->pointer == 0 && var.type() && var.type()->needInitialization == Type::False) + if (var.valueType()->pointer == 0 && var.type() && var.type()->needInitialization == Type::False && var.type()->derivedFrom.empty()) continue; if (var.isConst() && func.isOperator()) // We can't set const members in assignment operator @@ -193,7 +193,7 @@ void CheckClass::constructors() bool inconclusive = false; // Don't warn about unknown types in copy constructors since we // don't know if they can be copied or not.. - if ((func.type == Function::eCopyConstructor || func.type == Function::eOperatorEqual) && !isVariableCopyNeeded(var)) + if ((func.type == Function::eCopyConstructor || func.type == Function::eMoveConstructor || func.type == Function::eOperatorEqual) && !isVariableCopyNeeded(var)) inconclusive = true; if (!printInconclusive && inconclusive) diff --git a/test/testconstructors.cpp b/test/testconstructors.cpp index 42bb82323..61924bc0f 100644 --- a/test/testconstructors.cpp +++ b/test/testconstructors.cpp @@ -1356,6 +1356,25 @@ private: "};"); ASSERT_EQUALS("", errout.str()); + check("class A : public std::vector\n" + "{\n" + "public:\n" + " A(const A &a);\n" + "};\n" + "class B\n" + "{\n" + " A a;\n" + "public:\n" + " B(){}\n" + " B(const B&){}\n" + " B(B &&){}\n" + " const B& operator=(const B&){return *this;}\n" + "};", true); + ASSERT_EQUALS("[test.cpp:11]: (warning, inconclusive) Member variable 'B::a' is not initialized in the constructor.\n" + "[test.cpp:12]: (warning, inconclusive) Member variable 'B::a' is not initialized in the constructor.\n" + "[test.cpp:13]: (warning, inconclusive) Member variable 'B::a' is not assigned a value in 'B::operator='.\n", + errout.str()); + check("class B\n" "{\n" "public:\n"