]> gcc.gnu.org Git - gcc.git/commitdiff
c++: "perfect" implicitly deleted move [PR100644]
authorJason Merrill <jason@redhat.com>
Tue, 18 May 2021 16:06:36 +0000 (12:06 -0400)
committerJason Merrill <jason@redhat.com>
Tue, 18 May 2021 19:43:52 +0000 (15:43 -0400)
Here we were ignoring the template constructor because the implicit move
constructor had all perfect conversions.  But CWG1402 says that an
implicitly deleted move constructor is ignored by overload resolution; we
implement that instead by preferring any other candidate in joust, to get
better diagnostics, but that means we need to handle that case here as well.

gcc/cp/ChangeLog:

PR c++/100644
* call.c (perfect_candidate_p): An implicitly deleted move
is not perfect.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/implicit-delete1.C: New test.

gcc/cp/call.c
gcc/testsuite/g++.dg/cpp0x/implicit-delete1.C [new file with mode: 0644]

index 1e2d1d43184fc265a3b6182c96655e23d1f64f78..4a59b97c110526548d7ca458f2fe87deae9b4a28 100644 (file)
@@ -5890,6 +5890,11 @@ perfect_candidate_p (z_candidate *cand)
 {
   if (cand->viable < 1)
     return false;
+  /* CWG1402 makes an implicitly deleted move op worse than other
+     candidates.  */
+  if (DECL_DELETED_FN (cand->fn) && DECL_DEFAULTED_FN (cand->fn)
+      && move_fn_p (cand->fn))
+    return false;
   int len = cand->num_convs;
   for (int i = 0; i < len; ++i)
     if (!perfect_conversion_p (cand->convs[i]))
diff --git a/gcc/testsuite/g++.dg/cpp0x/implicit-delete1.C b/gcc/testsuite/g++.dg/cpp0x/implicit-delete1.C
new file mode 100644 (file)
index 0000000..6dcced4
--- /dev/null
@@ -0,0 +1,20 @@
+// PR c++/100644
+// { dg-do compile { target c++11 } }
+
+struct NonMovable {
+  NonMovable(NonMovable&&) = delete;
+};
+
+template <class T>
+struct Maybe {
+  NonMovable mMember;
+
+  template <typename U>
+  Maybe(Maybe<U>&&);
+};
+
+void foo(Maybe<int>);
+
+void unlucky(Maybe<int>&& x) {
+  Maybe<int> var{(Maybe<int>&&)x};
+}
This page took 0.082439 seconds and 5 git commands to generate.