Fix FP returnStdMoveLocal (#4244)

This commit is contained in:
chrchr-github 2022-06-30 13:50:31 +02:00 committed by GitHub
parent d8e64b4cbb
commit 27578e9c4c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -658,7 +658,7 @@ void CheckFunctions::returnLocalStdMove()
if (retval->variable() && retval->variable()->isLocal() && !retval->variable()->isVolatile())
copyElisionError(retval);
// RVO
if (Token::Match(retval, "(|{") && !retval->isCast())
if (Token::Match(retval, "(|{") && !retval->isCast() && !(retval->valueType() && retval->valueType()->reference != Reference::None))
copyElisionError(retval);
}
}

View File

@ -1731,6 +1731,18 @@ private:
check("struct A{} a; A f1() { return std::move(a); }\n"
"A f2() { volatile A var; return std::move(var); }");
ASSERT_EQUALS("", errout.str());
check("struct S { std::string msg{ \"abc\" }; };\n"
"std::unique_ptr<S> get(std::vector<std::unique_ptr<S>>& v) {\n"
" return std::move(v.front());\n"
"}\n"
"int main() {\n"
" std::vector<std::unique_ptr<S>> v;\n"
" v.emplace_back(std::make_unique<S>());\n"
" auto p = get(v);\n"
" std::cout << p->msg;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void negativeMemoryAllocationSizeError() { // #389