Skip to content

Commit 27578e9

Browse files
Fix FP returnStdMoveLocal (#4244)
1 parent d8e64b4 commit 27578e9

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

lib/checkfunctions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ void CheckFunctions::returnLocalStdMove()
658658
if (retval->variable() && retval->variable()->isLocal() && !retval->variable()->isVolatile())
659659
copyElisionError(retval);
660660
// RVO
661-
if (Token::Match(retval, "(|{") && !retval->isCast())
661+
if (Token::Match(retval, "(|{") && !retval->isCast() && !(retval->valueType() && retval->valueType()->reference != Reference::None))
662662
copyElisionError(retval);
663663
}
664664
}

test/testfunctions.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1731,6 +1731,18 @@ class TestFunctions : public TestFixture {
17311731
check("struct A{} a; A f1() { return std::move(a); }\n"
17321732
"A f2() { volatile A var; return std::move(var); }");
17331733
ASSERT_EQUALS("", errout.str());
1734+
1735+
check("struct S { std::string msg{ \"abc\" }; };\n"
1736+
"std::unique_ptr<S> get(std::vector<std::unique_ptr<S>>& v) {\n"
1737+
" return std::move(v.front());\n"
1738+
"}\n"
1739+
"int main() {\n"
1740+
" std::vector<std::unique_ptr<S>> v;\n"
1741+
" v.emplace_back(std::make_unique<S>());\n"
1742+
" auto p = get(v);\n"
1743+
" std::cout << p->msg;\n"
1744+
"}\n");
1745+
ASSERT_EQUALS("", errout.str());
17341746
}
17351747

17361748
void negativeMemoryAllocationSizeError() { // #389

0 commit comments

Comments
 (0)