Fixed #7987 (FP copyCtorAndEqOperator - class with a move constructor and move assignment operator)

This commit is contained in:
Daniel Marjamäki 2017-12-23 10:35:14 +01:00
parent 5ed2dbd5ef
commit 91839c2534
2 changed files with 19 additions and 0 deletions

View File

@ -2405,6 +2405,7 @@ void CheckClass::checkCopyCtorAndEqOperator()
continue;
CtorType copyCtors = CtorType::NO;
bool moveCtor = false;
CtorType assignmentOperators = CtorType::NO;
std::list<Function>::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);

View File

@ -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[]) {