c++: Quash bogus -Wredundant-move warning
commit8567d9491d06832ea34b564c6bace9f7d43099ae
authorMarek Polacek <polacek@redhat.com>
Mon, 22 Aug 2022 23:13:16 +0000 (22 19:13 -0400)
committerMarek Polacek <polacek@redhat.com>
Tue, 23 Aug 2022 22:40:14 +0000 (23 18:40 -0400)
treebb93432514f378c36483105f0dbf0284a62bf2f1
parent4ade41de1a6c80db6bb61399da6bff2126813d75
c++: Quash bogus -Wredundant-move warning

This patch fixes a pretty stoopid thinko.  When I added code to warn
about pessimizing std::move in initializations like

  T t{std::move(T())};

I also added code to unwrap the expression from { }.  But when we have

  return {std::move(t)};

we cannot warn about a redundant std::move because the implicit move
wouldn't happen for "return {t};" because the expression isn't just
a name.  However, we still want to warn about

  return {std::move(T())};

so let's not disable the -Wpessimizing-move warning.  Tests added for
both cases.

gcc/cp/ChangeLog:

* typeck.cc (maybe_warn_pessimizing_move): Don't warn about
redundant std::move when the expression was wrapped in { }.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/Wpessimizing-move10.C: New test.
* g++.dg/cpp0x/Wredundant-move12.C: New test.
gcc/cp/typeck.cc
gcc/testsuite/g++.dg/cpp0x/Wpessimizing-move10.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp0x/Wredundant-move12.C [new file with mode: 0644]