diff options
author | Marek Polacek <polacek@redhat.com> | 2022-08-01 17:02:23 -0400 |
---|---|---|
committer | Marek Polacek <polacek@redhat.com> | 2022-08-17 12:35:45 -0400 |
commit | 8d22c7cb8b1a6f9b67c54a798dd5504244614e51 (patch) | |
tree | 1c20cb245dd1cdb66727bde28f86ce9850e5e056 /gcc/cp/cp-tree.h | |
parent | 745be54bd6634fe63d6be83615e264c83d2ae9f9 (diff) | |
download | gcc-8d22c7cb8b1a6f9b67c54a798dd5504244614e51.zip gcc-8d22c7cb8b1a6f9b67c54a798dd5504244614e51.tar.gz gcc-8d22c7cb8b1a6f9b67c54a798dd5504244614e51.tar.bz2 |
c++: Extend -Wpessimizing-move to other contexts
In my recent patch which enhanced -Wpessimizing-move so that it warns
about class prvalues too I said that I'd like to extend it so that it
warns in more contexts where a std::move can prevent copy elision, such
as:
T t = std::move(T());
T t(std::move(T()));
T t{std::move(T())};
T t = {std::move(T())};
void foo (T);
foo (std::move(T()));
This patch does that by adding two maybe_warn_pessimizing_move calls.
These must happen before we've converted the initializers otherwise the
std::move will be buried in a TARGET_EXPR.
PR c++/106276
gcc/cp/ChangeLog:
* call.cc (build_over_call): Call maybe_warn_pessimizing_move.
* cp-tree.h (maybe_warn_pessimizing_move): Declare.
* decl.cc (build_aggr_init_full_exprs): Call
maybe_warn_pessimizing_move.
* typeck.cc (maybe_warn_pessimizing_move): Handle TREE_LIST and
CONSTRUCTOR. Add a bool parameter and use it. Adjust a diagnostic
message.
(check_return_expr): Adjust the call to maybe_warn_pessimizing_move.
gcc/testsuite/ChangeLog:
* g++.dg/cpp0x/Wpessimizing-move7.C: Add dg-warning.
* g++.dg/cpp0x/Wpessimizing-move8.C: New test.
Diffstat (limited to 'gcc/cp/cp-tree.h')
-rw-r--r-- | gcc/cp/cp-tree.h | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index cb239754..9f2ff37 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -8099,6 +8099,7 @@ extern tree finish_right_unary_fold_expr (tree, int); extern tree finish_binary_fold_expr (tree, tree, int); extern tree treat_lvalue_as_rvalue_p (tree, bool); extern bool decl_in_std_namespace_p (tree); +extern void maybe_warn_pessimizing_move (tree, tree, bool); /* in typeck2.cc */ extern void require_complete_eh_spec_types (tree, tree); |