Skip to content

[SUGGESTION] Already constructed object getting constructed again as we pass it as out parameter ? why ? #716

@jituderaps

Description

@jituderaps

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions