[Bug c++/93106] New: [c++2a] Deleted move constructor is not selected when returning an automatic variable
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93106 Bug ID: 93106 Summary: [c++2a] Deleted move constructor is not selected when returning an automatic variable Product: gcc Version: 9.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: ph3rin at gmail dot com Target Milestone: --- According to the c++ standard (draft n4835) the following code should not compile because it references a deleted function: struct not_movable { not_movable() = default; not_movable(not_movable const&) = default; not_movable(not_movable&&) = delete; }; not_movable foo() { not_movable obj; return obj; } When returning obj, the overload resolution should successfully select the deleted move constructor, therefore resulting in a compiler error. The code has been tested under gcc 9.2 with compiler flags -std=c++2a. Quotes from the standard: http://eel.is/c++draft/class.copy.elision#3
[Bug c++/93106] [c++2a] Deleted move constructor is not selected when returning an automatic variable
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93106 --- Comment #2 from Yunrui Wang --- (In reply to Jakub Jelinek from comment #1) > What you cite doesn't say anything that would make the testcase invalid. > The standard says that for an implicitly movable entity seen in return > statement shall first perform overload resolution for the copy constructor > as if it was an rvalue, which in this case fails because the move ctor is > deleted. And in that case, another overload resolution is performed, this > time considering the implicitly movable entity as lvalue, and that succeeds. > So, if copy-ellision wouldn't be performed, > not_movable::not_movable(not_movable const&) would be invoked, but in this > case copy-ellision is invoked and thus it is default constructed into the > return value object in the caller. The first overload resolution should succeed by selecting the deleted move constructors. Deleted functions are defined and are considered for overload resolution (unless otherwise specified - there are some edge cases, but not in this example).
[Bug c++/93106] [c++2a] Deleted move constructor is not selected when returning an automatic variable
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93106 Yunrui Wang changed: What|Removed |Added Status|NEW |RESOLVED Resolution|--- |FIXED --- Comment #8 from Yunrui Wang --- Issue has been resolved in gcc 12.1.