Skip to content

[BUG] variable used in if condition is moved despite it is used in the if statement #311

Closed
@filipsajdak

Description

@filipsajdak

In the current implementation of cppfront (b370ab8), the following code:

main: () = {
    b : bool = true;

    if b {
        std::cout << b << std::endl;
    }
}

Generates:

auto main() -> int{
    bool b {true}; 

    if (std::move(b)) {
        std::cout << std::move(b) << std::endl;
    }
}

The b variable is moved in the if condition despite its use in the if statement.

Adding the use of b after an if removes the move of b in the if condition and if statement which is correct.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions