This patch makes it easier to selectively disable
-Wvirtual-move-assign by allowing diagnostic pragmas on
base class move assignment operators to suppress such
warnings.
gcc/cp/ChangeLog:
* method.cc (synthesized_method_walk): Check whether
-Wvirtual-move-assign is enabled at the location of a base
class's move assignment operator.
gcc/testsuite/ChangeLog:
* g++.dg/warn/ignore-virtual-move-assign.C: New test.
Co-authored-by: Jason Merrill <jason@redhat.com>
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
&& BINFO_VIRTUAL_P (base_binfo)
&& fn && TREE_CODE (fn) == FUNCTION_DECL
&& move_fn_p (fn) && !trivial_fn_p (fn)
- && vbase_has_user_provided_move_assign (BINFO_TYPE (base_binfo)))
+ && vbase_has_user_provided_move_assign (BINFO_TYPE (base_binfo))
+ && warning_enabled_at (DECL_SOURCE_LOCATION (fn),
+ OPT_Wvirtual_move_assign))
warning (OPT_Wvirtual_move_assign,
"defaulted move assignment for %qT calls a non-trivial "
"move assignment operator for virtual base %qT",
--- /dev/null
+// { dg-do compile { target c++11 } }
+// { dg-options "-Wvirtual-move-assign -Wattributes" }
+
+#include <utility>
+
+class A
+{
+ int val;
+
+public:
+ explicit A (int val) : val (val) {}
+
+ A (const A &oth) : val (0) {}
+ A &operator= (const A &oth) { return *this; }
+ A (A &&oth) : val (oth.val) { oth.val = 0; }
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wvirtual-move-assign"
+ A &operator= (A &&oth)
+ {
+ val += oth.val;
+ oth.val = 0;
+ return *this;
+ }
+#pragma GCC diagnostic pop
+};
+
+class B : virtual A
+{
+public:
+ B () : A (12) {}
+ B &operator= (B &&) = default;
+};
+
+class C : virtual A
+{
+public:
+ C () : A (12) {}
+};
+
+void
+test_fn ()
+{
+ C x, y;
+ x = std::move (y);
+}