public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/100644] New: [11 regression] Deleted move constructor prevents templated constructor from being used
@ 2021-05-18  0:55 botond at mozilla dot com
  2021-05-18  6:21 ` [Bug c++/100644] [11/12 " rguenth at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: botond at mozilla dot com @ 2021-05-18  0:55 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100644

            Bug ID: 100644
           Summary: [11 regression] Deleted move constructor prevents
                    templated constructor from being used
           Product: gcc
           Version: 11.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: botond at mozilla dot com
  Target Milestone: ---

GCC 11 gives an error for the following code which GCC 10 and Clang accept:


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};
}


The error is:


main.cpp: In function ‘void unlucky(Maybe<int>&&)’:
main.cpp:16:33: error: use of deleted function
‘Maybe<int>::Maybe(Maybe<int>&&)’
   16 |   Maybe<int> var{(Maybe<int>&&)x};
      |                                 ^
main.cpp:6:8: note: ‘Maybe<int>::Maybe(Maybe<int>&&)’ is implicitly deleted
because the default definition would be ill-formed:
    6 | struct Maybe {
      |        ^~~~~
main.cpp:6:8: error: use of deleted function
‘NonMovable::NonMovable(NonMovable&&)’
main.cpp:2:3: note: declared here
    2 |   NonMovable(NonMovable &&) = delete;
      |   ^~~~~~~~~~


I believe the code should be accepted, with the deleted move constructor
ignored during overload resolution and the templated constructor used instead.

I explain my reasoning, with links to the standard, in more detail here:
https://bugzilla.mozilla.org/show_bug.cgi?id=1710235#c22

Please let me know if I've overlooked something and the code really is invalid.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/100644] [11/12 regression] Deleted move constructor prevents templated constructor from being used
  2021-05-18  0:55 [Bug c++/100644] New: [11 regression] Deleted move constructor prevents templated constructor from being used botond at mozilla dot com
@ 2021-05-18  6:21 ` rguenth at gcc dot gnu.org
  2021-05-18  8:54 ` redi at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-05-18  6:21 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100644

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |11.2
      Known to work|                            |10.3.0
            Summary|[11 regression] Deleted     |[11/12 regression] Deleted
                   |move constructor prevents   |move constructor prevents
                   |templated constructor from  |templated constructor from
                   |being used                  |being used
           Keywords|                            |rejects-valid

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/100644] [11/12 regression] Deleted move constructor prevents templated constructor from being used
  2021-05-18  0:55 [Bug c++/100644] New: [11 regression] Deleted move constructor prevents templated constructor from being used botond at mozilla dot com
  2021-05-18  6:21 ` [Bug c++/100644] [11/12 " rguenth at gcc dot gnu.org
@ 2021-05-18  8:54 ` redi at gcc dot gnu.org
  2021-05-18 15:57 ` jason at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2021-05-18  8:54 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100644

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu.org

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Rejected since r11-7287

    c++: Tuple of self-dependent classes [PR96926]

    When compiling this testcase, trying to resolve the initialization for the
    tuple member ends up recursively considering the same set of tuple
    constructor overloads, and since two of them separately depend on
    is_constructible, the one we try second fails to instantiate
    is_constructible because we're still in the middle of instantiating it the
    first time.

    Fixed by implementing an optimization that someone suggested we were
already
    doing: if we see a non-template candidate that is a perfect match for all
    arguments, we can skip considering template candidates at all.  It would be
    enough to do this only when LOOKUP_DEFAULTED, but it shouldn't hurt in
other
    cases.

    gcc/cp/ChangeLog:

            PR c++/96926
            * call.c (perfect_conversion_p): New.
            (perfect_candidate_p): New.
            (add_candidates): Ignore templates after a perfect non-template.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/100644] [11/12 regression] Deleted move constructor prevents templated constructor from being used
  2021-05-18  0:55 [Bug c++/100644] New: [11 regression] Deleted move constructor prevents templated constructor from being used botond at mozilla dot com
  2021-05-18  6:21 ` [Bug c++/100644] [11/12 " rguenth at gcc dot gnu.org
  2021-05-18  8:54 ` redi at gcc dot gnu.org
@ 2021-05-18 15:57 ` jason at gcc dot gnu.org
  2021-05-18 19:44 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: jason at gcc dot gnu.org @ 2021-05-18 15:57 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100644

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2021-05-18
             Status|UNCONFIRMED                 |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |jason at gcc dot gnu.org
     Ever confirmed|0                           |1

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/100644] [11/12 regression] Deleted move constructor prevents templated constructor from being used
  2021-05-18  0:55 [Bug c++/100644] New: [11 regression] Deleted move constructor prevents templated constructor from being used botond at mozilla dot com
                   ` (2 preceding siblings ...)
  2021-05-18 15:57 ` jason at gcc dot gnu.org
@ 2021-05-18 19:44 ` cvs-commit at gcc dot gnu.org
  2021-05-18 21:19 ` cvs-commit at gcc dot gnu.org
  2021-05-19 20:19 ` jason at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-05-18 19:44 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100644

--- Comment #2 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jason Merrill <jason@gcc.gnu.org>:

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.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/100644] [11/12 regression] Deleted move constructor prevents templated constructor from being used
  2021-05-18  0:55 [Bug c++/100644] New: [11 regression] Deleted move constructor prevents templated constructor from being used botond at mozilla dot com
                   ` (3 preceding siblings ...)
  2021-05-18 19:44 ` cvs-commit at gcc dot gnu.org
@ 2021-05-18 21:19 ` cvs-commit at gcc dot gnu.org
  2021-05-19 20:19 ` jason at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-05-18 21:19 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100644

--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Jason Merrill
<jason@gcc.gnu.org>:

https://gcc.gnu.org/g:6384e940a6db379b0524465cf6cbbd0996b48485

commit r11-8431-g6384e940a6db379b0524465cf6cbbd0996b48485
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.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/100644] [11/12 regression] Deleted move constructor prevents templated constructor from being used
  2021-05-18  0:55 [Bug c++/100644] New: [11 regression] Deleted move constructor prevents templated constructor from being used botond at mozilla dot com
                   ` (4 preceding siblings ...)
  2021-05-18 21:19 ` cvs-commit at gcc dot gnu.org
@ 2021-05-19 20:19 ` jason at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: jason at gcc dot gnu.org @ 2021-05-19 20:19 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100644

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #4 from Jason Merrill <jason at gcc dot gnu.org> ---
Fixed for 11.2/12.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-05-19 20:19 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-18  0:55 [Bug c++/100644] New: [11 regression] Deleted move constructor prevents templated constructor from being used botond at mozilla dot com
2021-05-18  6:21 ` [Bug c++/100644] [11/12 " rguenth at gcc dot gnu.org
2021-05-18  8:54 ` redi at gcc dot gnu.org
2021-05-18 15:57 ` jason at gcc dot gnu.org
2021-05-18 19:44 ` cvs-commit at gcc dot gnu.org
2021-05-18 21:19 ` cvs-commit at gcc dot gnu.org
2021-05-19 20:19 ` jason at gcc dot gnu.org

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).