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.