PR c++/86981, Implement -Wpessimizing-move.
authorMarek Polacek <polacek@redhat.com>
Tue, 21 Aug 2018 15:38:36 +0000 (15:38 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Tue, 21 Aug 2018 15:38:36 +0000 (15:38 +0000)
commit79ca9c3596a2de77d953cc84e31150051f4d2441
treeb04486ba9b0aaa7af7f595797d4939cc9fa32b38
parent992931ba3d02d107b3abf51781b4b4625d2cce7c
PR c++/86981, Implement -Wpessimizing-move.

* c.opt (Wpessimizing-move): New option.

* typeck.c (decl_in_std_namespace_p): New.
(is_std_move_p): New.
(maybe_warn_pessimizing_move): New.
(can_do_nrvo_p): New, factored out of ...
(check_return_expr): ... here.  Warn about potentially harmful
std::move in a return statement.

* doc/invoke.texi: Document -Wpessimizing-move.

* g++.dg/cpp0x/Wpessimizing-move1.C: New test.
* g++.dg/cpp0x/Wpessimizing-move2.C: New test.
* g++.dg/cpp0x/Wpessimizing-move3.C: New test.
* g++.dg/cpp0x/Wpessimizing-move4.C: New test.
* g++.dg/cpp1z/Wpessimizing-move1.C: New test.

From-SVN: r263741
12 files changed:
gcc/ChangeLog
gcc/c-family/ChangeLog
gcc/c-family/c.opt
gcc/cp/ChangeLog
gcc/cp/typeck.c
gcc/doc/invoke.texi
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/Wpessimizing-move1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp0x/Wpessimizing-move2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp0x/Wpessimizing-move3.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp0x/Wpessimizing-move4.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp1z/Wpessimizing-move1.C [new file with mode: 0644]