public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-885] c++: "perfect" implicitly deleted move [PR100644]
@ 2021-05-18 19:44 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2021-05-18 19:44 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:f71ca97def69b8aeb046d716eaea2367736f505e

commit r12-885-gf71ca97def69b8aeb046d716eaea2367736f505e
Author: Jason Merrill <jason@redhat.com>
Date:   Tue May 18 12:06:36 2021 -0400

    c++: "perfect" implicitly deleted move [PR100644]
    
    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.

Diff:
---
 gcc/cp/call.c                                 |  5 +++++
 gcc/testsuite/g++.dg/cpp0x/implicit-delete1.C | 20 ++++++++++++++++++++
 2 files changed, 25 insertions(+)

diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 1e2d1d43184..4a59b97c110 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -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
index 00000000000..6dcced4fb2d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/implicit-delete1.C
@@ -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};
+}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-05-18 19:44 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-18 19:44 [gcc r12-885] c++: "perfect" implicitly deleted move [PR100644] Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).