下面的代码:
#include <iostream>
struct A {
A() { std::cout << "()" << std::endl; }
A(A&&) { std::cout << "(A&&)" << std::endl; }
A(const A&) { std::cout << "(const A&)" << std::endl; }
};
A fun (A&& a){
return a;
}
int main(){
A a;
fun(std::move(a));
return 0;
}
Run Code Online (Sandbox Code Playgroud)
在 clang 16.0.3 (arm64-apple-darwin22.4.0 和 c++17) 中产生
()
(A&&)
Run Code Online (Sandbox Code Playgroud)
虽然大多数编译器给出
()
(const A&)
Run Code Online (Sandbox Code Playgroud)
哪一个是正确的?