CALL_EXPR_ORDERED_ARGS (call) = ord;
CALL_EXPR_REVERSE_ARGS (call) = rev;
}
+ if (warning_suppressed_p (t, OPT_Wpessimizing_move))
+ /* This also suppresses -Wredundant-move. */
+ suppress_warning (ret, OPT_Wpessimizing_move);
}
RETURN (ret);
else if (can_do_nrvo_p (arg, type))
{
auto_diagnostic_group d;
- if (warning_at (loc, OPT_Wpessimizing_move,
- "moving a local object in a return statement "
- "prevents copy elision"))
+ if (!warning_suppressed_p (expr, OPT_Wpessimizing_move)
+ && warning_at (loc, OPT_Wpessimizing_move,
+ "moving a local object in a return statement "
+ "prevents copy elision"))
inform (loc, "remove %<std::move%> call");
}
/* Warn if the move is redundant. It is redundant when we would
do maybe-rvalue overload resolution even without std::move. */
else if (warn_redundant_move
+ && !warning_suppressed_p (expr, OPT_Wredundant_move)
&& (moved = treat_lvalue_as_rvalue_p (arg, /*return*/true)))
{
/* Make sure that overload resolution would actually succeed
/* We don't know if this is an lvalue or rvalue use, but
either way we can mark it as read. */
mark_exp_read (retval);
+ /* Disable our std::move warnings when we're returning
+ a dependent expression (c++/89780). */
+ if (retval && TREE_CODE (retval) == CALL_EXPR)
+ /* This also suppresses -Wredundant-move. */
+ suppress_warning (retval, OPT_Wpessimizing_move);
return retval;
}
case OPT_Winit_self:
case OPT_Wuninitialized:
case OPT_Wmaybe_uninitialized:
- m_bits = NW_UNINIT;
+ m_bits = NW_UNINIT;
break;
case OPT_Wdangling_pointer_:
m_bits = NW_DANGLING;
break;
+ case OPT_Wpessimizing_move:
+ case OPT_Wredundant_move:
+ m_bits = NW_REDUNDANT;
+ break;
+
default:
/* A catchall group for everything else. */
m_bits = NW_OTHER;
NW_DANGLING = 1 << 5,
/* All other unclassified warnings. */
NW_OTHER = 1 << 6,
+ /* Warnings about redundant calls. */
+ NW_REDUNDANT = 1 << 7,
/* All groups of warnings. */
NW_ALL = (NW_ACCESS | NW_LEXICAL | NW_NONNULL
- | NW_UNINIT | NW_VFLOW | NW_DANGLING | NW_OTHER)
+ | NW_UNINIT | NW_VFLOW | NW_DANGLING | NW_REDUNDANT | NW_OTHER)
};
nowarn_spec_t (): m_bits () { }
fn2 ()
{
Tp2 t;
- return std::move (t); // { dg-warning "moving a local object in a return statement prevents copy elision" }
+ return std::move (t);
}
template<typename Tp1, typename Tp2>
--- /dev/null
+// PR c++/89780
+// { dg-do compile { target c++11 } }
+// { dg-options "-Wpessimizing-move -Wredundant-move" }
+
+// Define std::move.
+namespace std {
+ template<typename _Tp>
+ struct remove_reference
+ { typedef _Tp type; };
+
+ template<typename _Tp>
+ struct remove_reference<_Tp&>
+ { typedef _Tp type; };
+
+ template<typename _Tp>
+ struct remove_reference<_Tp&&>
+ { typedef _Tp type; };
+
+ template<typename _Tp>
+ constexpr typename std::remove_reference<_Tp>::type&&
+ move(_Tp&& __t) noexcept
+ { return static_cast<typename std::remove_reference<_Tp>::type&&>(__t); }
+}
+
+struct Dest {
+ Dest() = default;
+ Dest(Dest&&);
+ Dest(const Dest&);
+};
+struct Source : Dest {};
+
+template <typename T>
+Dest withMove() {
+ T x;
+ return std::move(x);
+}
+
+template Dest withMove<Dest>();
+template Dest withMove<Source>();
+
+template<typename T>
+Dest bar () {
+ return std::move(T()); // { dg-warning "moving a temporary object prevents copy elision" }
+}
+
+template Dest bar<Dest>();
+template Dest bar<Source>();
+
+template<typename T>
+Dest baz (T x) {
+ return std::move(x);
+}
+
+void
+call_baz ()
+{
+ Dest d;
+ Source s;
+ baz (d);
+ baz (s);
+}
+
+template<typename>
+Dest foo ()
+{
+ Dest d;
+ return std::move(d); // { dg-warning "moving a local object in a return statement prevents copy elision" }
+}
+
+template Dest foo<int>();
+
+template<typename>
+Dest qux () {
+ return std::move(Dest()); // { dg-warning "moving a temporary object prevents copy elision" }
+}
+
+template Dest qux<int>();
+
+template<typename>
+Dest qui (Dest x) {
+ return std::move(x); // { dg-warning "redundant move in return statement" }
+}
+
+void
+call_qui ()
+{
+ Dest d;
+ qui<int> (d);
+}
Tp1
fn2 (Tp2 t)
{
- return std::move (t); // { dg-warning "redundant move in return statement" }
+ return std::move (t);
}
template<typename Tp1, typename Tp2>
Tp1
fn3 (Tp2 t)
{
- return std::move (t); // { dg-warning "redundant move in return statement" }
+ return std::move (t);
}
int