Fix FP returnStdMoveLocal (#4244)
This commit is contained in:
parent
d8e64b4cbb
commit
27578e9c4c
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue