On 5/12/25 5:03 PM, Owen Avery wrote:
Please add a little rationale for the change here, perhaps adapting the
one from your previous patch.
gcc/cp/ChangeLog:
* method.cc
(synthesized_method_walk): Check whether -Wvirtual-move-assign
The (function) should usually go on the same line as the source file.
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 <ja...@redhat.com>
Signed-off-by: Owen Avery <powerboat9.ga...@gmail.com>
---
gcc/cp/method.cc | 4 +-
.../g++.dg/warn/ignore-virtual-move-assign.C | 45 +++++++++++++++++++
2 files changed, 48 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/g++.dg/warn/ignore-virtual-move-assign.C
diff --git a/gcc/cp/method.cc b/gcc/cp/method.cc
index 05c19cf0661..092bae27787 100644
--- a/gcc/cp/method.cc
+++ b/gcc/cp/method.cc
@@ -2949,7 +2949,9 @@ synthesized_method_walk (tree ctype,
special_function_kind sfk, bool const_p,
&& 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",
diff --git a/gcc/testsuite/g++.dg/warn/ignore-virtual-move-assign.C
b/gcc/testsuite/g++.dg/warn/ignore-virtual-move-assign.C
new file mode 100644
index 00000000000..73922e69754
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/ignore-virtual-move-assign.C
@@ -0,0 +1,45 @@
+// { 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);
+}