[Bug c++/67200] New: Copy elision and implicit move in return performed in cases not allowed by standard
rs2740 at gmail dot com
gcc-bugzilla@gcc.gnu.org
Thu Aug 13 05:25:00 GMT 2015
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67200
Bug ID: 67200
Summary: Copy elision and implicit move in return performed in
cases not allowed by standard
Product: gcc
Version: 6.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: rs2740 at gmail dot com
Target Milestone: ---
Consider:
struct A {
A() = default;
A(const A&) = delete;
A(A&&) = default;
};
A f() {
A a;
return true ? a : a;
}
This code is ill-formed; `true ? a : a` is an lvalue of type `A`; it neither
qualifies for copy elision under [class.copy]/p31 (it is not "the name of a
nonvolatile
automatic object") nor for implicit moving under [class.copy]/p32 (it's not an
id-expression, either). Therefore, overload resolution should select the copy
constructor, which in the above example is deleted.
GCC compiles this code and in fact elides a move.
More information about the Gcc-bugs
mailing list