Fixed #7987 (FP copyCtorAndEqOperator - class with a move constructor and move assignment operator)
This commit is contained in:
parent
5ed2dbd5ef
commit
91839c2534
|
@ -2405,6 +2405,7 @@ void CheckClass::checkCopyCtorAndEqOperator()
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
CtorType copyCtors = CtorType::NO;
|
CtorType copyCtors = CtorType::NO;
|
||||||
|
bool moveCtor = false;
|
||||||
CtorType assignmentOperators = CtorType::NO;
|
CtorType assignmentOperators = CtorType::NO;
|
||||||
|
|
||||||
std::list<Function>::const_iterator func;
|
std::list<Function>::const_iterator func;
|
||||||
|
@ -2418,8 +2419,15 @@ void CheckClass::checkCopyCtorAndEqOperator()
|
||||||
assignmentOperators = func->hasBody() ? CtorType::WITH_BODY : CtorType::WITHOUT_BODY;
|
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) ||
|
if ((copyCtors == CtorType::WITH_BODY && assignmentOperators == CtorType::NO) ||
|
||||||
(copyCtors == CtorType::NO && assignmentOperators == CtorType::WITH_BODY))
|
(copyCtors == CtorType::NO && assignmentOperators == CtorType::WITH_BODY))
|
||||||
copyCtorAndEqOperatorError(scope->classDef, scope->className, scope->type == Scope::eStruct, copyCtors == CtorType::WITH_BODY);
|
copyCtorAndEqOperatorError(scope->classDef, scope->className, scope->type == Scope::eStruct, copyCtors == CtorType::WITH_BODY);
|
||||||
|
|
|
@ -276,6 +276,17 @@ private:
|
||||||
" static int i;\n"
|
" static int i;\n"
|
||||||
"};");
|
"};");
|
||||||
ASSERT_EQUALS("", errout.str());
|
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[]) {
|
void checkExplicitConstructors(const char code[]) {
|
||||||
|
|
Loading…
Reference in New Issue