https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87300
Bug ID: 87300 Summary: -Wredundant-move gives false positives in C++11 mode Product: gcc Version: 9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: steinar+gcc at gunderson dot no Target Milestone: --- Hi, -Wredundant-move sometimes gives false positives in C++11 mode -- the std::move calls are simply not redundant. Case in point: atum17:~> cat test.cc #include <memory> #include <utility> class B {}; class D : public B {}; std::unique_ptr<B> foo() { std::unique_ptr<D> d; return std::move(d); } atum17:~> /usr/lib/gcc-snapshot/bin/g++ -std=c++11 -Wall -Wextra -c test.cc test.cc: In function 'std::unique_ptr<B> foo()': test.cc:9:19: warning: redundant move in return statement [-Wredundant-move] 9 | return std::move(d); | ~~~~~~~~~^~~ test.cc:9:19: note: remove 'std::move' call If you follow the warning and remove the std::move() call, GCC will still allow the program, but that's an extension; it's malformed in C++11, and Solaris Developer Studio rejects it. The rule that returns of NRVO-capable objects should look for overloads as if the return value were an rvalue went into effect only in C++14, from what I can see (DR1579, http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1579). gcc version 9.0.0 20180908 (experimental) [trunk revision 264170] (Debian 20180908-1)