From 91839c253489f52c100c19bd1d08a222bcc56573 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 23 Dec 2017 10:35:14 +0100 Subject: [PATCH] Fixed #7987 (FP copyCtorAndEqOperator - class with a move constructor and move assignment operator) --- lib/checkclass.cpp | 8 ++++++++ test/testclass.cpp | 11 +++++++++++ 2 files changed, 19 insertions(+) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index d300e547a..6946fc29d 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -2405,6 +2405,7 @@ void CheckClass::checkCopyCtorAndEqOperator() continue; CtorType copyCtors = CtorType::NO; + bool moveCtor = false; CtorType assignmentOperators = CtorType::NO; std::list::const_iterator func; @@ -2418,8 +2419,15 @@ void CheckClass::checkCopyCtorAndEqOperator() assignmentOperators = func->hasBody() ? CtorType::WITH_BODY : CtorType::WITHOUT_BODY; } } + if (func->type == Function::eMoveConstructor) { + moveCtor = true; + break; + } } + if (moveCtor) + continue; + if ((copyCtors == CtorType::WITH_BODY && assignmentOperators == CtorType::NO) || (copyCtors == CtorType::NO && assignmentOperators == CtorType::WITH_BODY)) copyCtorAndEqOperatorError(scope->classDef, scope->className, scope->type == Scope::eStruct, copyCtors == CtorType::WITH_BODY); diff --git a/test/testclass.cpp b/test/testclass.cpp index fc41eabca..347881246 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -276,6 +276,17 @@ private: " static int i;\n" "};"); ASSERT_EQUALS("", errout.str()); + + // #7987 - Don't show warning when there is a move constructor + checkCopyCtorAndEqOperator("struct S {\n" + " std::string test;\n" + " S(S&& s) : test(std::move(s.test)) { }\n" + " S& operator = (S &&s) {\n" + " test = std::move(s.test);\n" + " return *this;\n" + " }\n" + "};\n"); + ASSERT_EQUALS("", errout.str()); } void checkExplicitConstructors(const char code[]) {