[Bug c++/89780] -Wpessimizing-move is too agressive with templates and recommends pessimization

mpolacek at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Aug 4 21:03:58 GMT 2022


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89780

--- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
(In reply to S. Davis Herring from comment #3)
> Does this need to be language-version-dependent, given
> https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1825r0.html (in
> C++20) and
> https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2266r3.html (in
> C++23)?

So far I couldn't find a testcase where we either
1) say that a std::move is pessimizing while it's only redundant, or
2) don't say that a std::move is redundant when it is, under the new rules.

I don't think we fully implement p2266r3 yet, maybe once we do, the warning
will have to be adjusted.

For instance, this

struct S1 { S1(); S1(S1 &&); };
struct S2 : S1 {};

S1
f (S2 s)
{
  return std::move(s);
}

with -std=c++20 will warn about a redundant move in the return statement.  In
C++17 it will not compile because the deleted S1(const S1&) is used.


More information about the Gcc-bugs mailing list