result = build_min_nt_call_vec (orig_fn, *args);
SET_EXPR_LOCATION (result, cp_expr_loc_or_input_loc (fn));
KOENIG_LOOKUP_P (result) = koenig_p;
+ /* Disable the std::move warnings since this call was dependent
+ (c++/89780, c++/107363). This also suppresses the
+ -Wredundant-move warning. */
+ suppress_warning (result, OPT_Wpessimizing_move);
if (is_overloaded_fn (fn))
fn = get_fns (fn);
and where the std::move does nothing if T does not have a T(const T&&)
constructor, because the argument is const. It will not use T(T&&)
because that would mean losing the const. */
- else if (TYPE_REF_P (TREE_TYPE (arg))
+ else if (warn_redundant_move
+ && !warning_suppressed_p (expr, OPT_Wredundant_move)
+ && TYPE_REF_P (TREE_TYPE (arg))
&& CP_TYPE_CONST_P (TREE_TYPE (TREE_TYPE (arg))))
{
tree rtype = TREE_TYPE (TREE_TYPE (arg));
return;
}
auto_diagnostic_group d;
- if (warning_at (loc, OPT_Wredundant_move,
- "redundant move in return statement"))
+ if (return_p
+ ? warning_at (loc, OPT_Wredundant_move,
+ "redundant move in return statement")
+ : warning_at (loc, OPT_Wredundant_move,
+ "redundant move in initialization"))
inform (loc, "remove %<std::move%> call");
}
}
/* 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;
}
--- /dev/null
+// PR c++/107363
+// { dg-do compile { target c++11 } }
+// { dg-options "-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); }
+}
+
+template <typename T, typename U>
+struct Optional {
+ U &value();
+ T release_value() {
+ T t = std::move (value ());
+ return t;
+ }
+};
+
+struct Foo {};
+void test(Optional<const Foo, const Foo> o) { o.release_value(); }
+
+struct F {
+ F(const F&);
+ F(F&&) = delete;
+};
+
+struct Z {
+ Z(const Z&) = delete;
+ Z(Z&&) = delete;
+ Z(const Z&&);
+};
+
+const F& constfref();
+const Z& constzref();
+
+void
+g ()
+{
+ // Will call F::F(const F&) w/ and w/o std::move. So it's redundant.
+ F f = std::move (constfref()); // { dg-warning "redundant move in initialization" }
+ (void) f;
+ // Will call Z::Z(const Z&&) w/ std::move, and Z::Z(const Z&) w/o.
+ // So it's not redundant.
+ Z z = std::move (constzref());
+ (void) z;
+}