[cfe-dev] return lvalue move instead of copy?
Stephan Bergmann via cfe-dev
cfe-dev at lists.llvm.org
Wed Aug 29 01:38:03 PDT 2018
Given code like
struct S1 { S1(S1 &&); };
struct S2: S1 {};
S1 f(S2 s) { return s; }
and the rules for when s in the return statement is treated like an
rvalue when picking the ctor to use ([class.copy.elision]/3 in C++17,
[class.copy]/32 in C++14, and [class.copy]/32 plus CWG1579 in C++11), my
interpretation is that the code is correct and should pick the S1 move ctor.
However, any version of Clang up to recent trunk rejects the code,
trying to call the implicitly deleted S1 copy ctor. GCC >= 8.1 accepts
the code, and I wonder whether Clang or GCC (and my interpretation) is
wrong.
More information about the cfe-dev
mailing list