+2019-03-06 Marek Polacek <polacek@redhat.com>
+
+ PR c++/87378 - bogus -Wredundant-move warning.
+ * typeck.c (maybe_warn_pessimizing_move): See if the maybe-rvalue
+ overload resolution would actually succeed.
+
2019-03-05 Jason Merrill <jason@redhat.com>
* class.c (is_really_empty_class): Add ignore_vptr parm.
do maybe-rvalue overload resolution even without std::move. */
else if (treat_lvalue_as_rvalue_p (arg, /*parm_ok*/true))
{
- auto_diagnostic_group d;
- if (warning_at (loc, OPT_Wredundant_move,
- "redundant move in return statement"))
- inform (loc, "remove %<std::move%> call");
+ /* Make sure that the overload resolution would actually succeed
+ if we removed the std::move call. */
+ tree t = convert_for_initialization (NULL_TREE, functype,
+ move (arg),
+ (LOOKUP_NORMAL
+ | LOOKUP_ONLYCONVERTING
+ | LOOKUP_PREFER_RVALUE),
+ ICR_RETURN, NULL_TREE, 0,
+ tf_none);
+ /* If this worked, implicit rvalue would work, so the call to
+ std::move is redundant. */
+ if (t != error_mark_node)
+ {
+ auto_diagnostic_group d;
+ if (warning_at (loc, OPT_Wredundant_move,
+ "redundant move in return statement"))
+ inform (loc, "remove %<std::move%> call");
+ }
}
}
}
+2019-03-06 Marek Polacek <polacek@redhat.com>
+
+ PR c++/87378 - bogus -Wredundant-move warning.
+ * g++.dg/cpp0x/Wredundant-move1.C (fn4): Drop dg-warning.
+ * g++.dg/cpp0x/Wredundant-move7.C: New test.
+
2019-03-06 Richard Biener <rguenther@suse.de>
PR testsuite/89551
fn4 (const T t)
{
// t is const: will decay into copy despite std::move, so it's redundant.
- return std::move (t); // { dg-warning "redundant move in return statement" }
+ // We used to warn about this, but no longer since c++/87378.
+ return std::move (t);
}
int
--- /dev/null
+// PR c++/87378
+// { 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); }
+}
+
+struct S1 { S1(S1 &&); };
+struct S2 : S1 {};
+
+S1
+f (S2 s)
+{
+ return std::move(s); // { dg-bogus "redundant move in return statement" }
+}
+
+struct R1 {
+ R1(R1 &&);
+ R1(const R1 &&);
+};
+struct R2 : R1 {};
+
+R1
+f2 (const R2 s)
+{
+ return std::move(s); // { dg-bogus "redundant move in return statement" }
+}
+
+struct T1 {
+ T1(const T1 &);
+ T1(T1 &&);
+ T1(const T1 &&);
+};
+struct T2 : T1 {};
+
+T1
+f3 (const T2 s)
+{
+ // Without std::move: const T1 &
+ // With std::move: const T1 &&
+ return std::move(s); // { dg-bogus "redundant move in return statement" }
+}