You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[SUGGESTION] Already constructed object getting constructed again as we pass it as out parameter ? why ? #716
AFAIK, the motive of out parameter is to accept an object(i.e. not constructed yet) and construct it, but what if we pass an already constructed object as out argument, it will get constructed / assigned again and that is inefficient.
for example :
demo of similar problem to understand the construction of object: https://cpp2.godbolt.org/z/zhYo997ad
fun: (out x: int) = x = 5;
main: () -> i32 = {
v1: int = 9;
// v2: int;
fun(out v1); // it should be illegal because it's inefficient (doesn't define the meaning of out parameter)
// fun(out v2); // works fine
}
Expected result : compilation error
Actual result/error : running fine
Activity
JohelEGP commentedon Oct 2, 2023
That's like suggesting to ban
v1 = 10becausev1is already constructed.=on an initialized variable already behaves like anoutargument.For more, see https://github.com/hsutter/cppfront/wiki/Cpp2:-operator=,-this-&-that#misc-notes.