File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments