-
Notifications
You must be signed in to change notification settings - Fork 259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Cannot return object of type by value #400
Comments
The error is clear.
So a |
See also https://wg21.link/P2573. |
Should baz() still work? |
Yes. That looks OK. |
Well I still not fully understand. Isn't foo() supposed to not copy, but move by cpp2 default? Error rises inside std::remove_reference which for me looks like some inner workings, not what I am expressing in cpp2. |
Copy and move are an overload set. |
I think On other hand, in
Also I tried |
That's right. Returning a prvalue doesn't require copy/move.
Or an
That's subject of #231. |
Thanks for the usability report, and I like the error message suggestion. Applied! |
Cpp1 error when trying to return object (by value?) from local variable
Code example
S : type = {
public x: int = 42;
}
baz: () -> _ = {
return S(); //ok cpp1: return S();
}
foo: () -> _ = {
//foo: () -> move _ = { //same behavior
s: S = ();
return s; //cpp1 error: see below
}
main: () = {
std::cout << baz().x;
std::cout << foo().x;
}
Actual result - cpp1 error
Additional info
it is possible to return just constructed object like in baz()
Probably this is desired, but I dont see much difference why local cannot be returned here, and constructed object can.
Another note, it is working if type declared with @struct meta
The text was updated successfully, but these errors were encountered: