On Mon, Aug 22, 2022 at 01:48:34PM +0200, Stephan Bergmann wrote: > On 16/08/2022 14:27, Marek Polacek via Gcc-patches wrote: > > Ping. (The other std::move patches depend on this one.) > > <https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=8d22c7cb8b1a6f9b67c54a798dd5504244614e51> > "c++: Extend -Wpessimizing-move to other contexts" started to cause false > positive
Thanks for reporting the problem. I'm testing a simple patch (appended below) and will post it once testing finishes. > > $ cat test.cc > > #include <utility> > > struct S1 { > > S1(); > > S1(S1 const &) = delete; > > S1(S1 &&); > > S1 operator =(S1 const &) = delete; > > S1 operator =(S1 &&); > > }; > > struct S2 { S2(S1); }; > > S2 f() { > > S1 s; > > return { std::move(s) }; > > } > > > > $ g++ -fsyntax-only -Wredundant-move test.cc > > test.cc: In function ‘S2 f()’: > > test.cc:12:27: warning: redundant move in return statement > > [-Wredundant-move] > > 12 | return { std::move(s) }; > > | ^ > > test.cc:12:27: note: remove ‘std::move’ call --- a/gcc/cp/typeck.cc +++ b/gcc/cp/typeck.cc @@ -10447,7 +10447,7 @@ maybe_warn_pessimizing_move (tree expr, tree type, bool return_p) return; /* A a = std::move (A()); */ - if (TREE_CODE (expr) == TREE_LIST) + if (TREE_CODE (expr) == TREE_LIST && !return_p) { if (list_length (expr) == 1) expr = TREE_VALUE (expr); @@ -10456,7 +10456,7 @@ maybe_warn_pessimizing_move (tree expr, tree type, bool return_p) } /* A a = {std::move (A())}; A a{std::move (A())}; */ - else if (TREE_CODE (expr) == CONSTRUCTOR) + else if (TREE_CODE (expr) == CONSTRUCTOR && !return_p) { if (CONSTRUCTOR_NELTS (expr) == 1) expr = CONSTRUCTOR_ELT (expr, 0)->value; Marek