Skip to content

[BUG] No implicit move or forward on last use in initialization #749

Closed
@JohelEGP

Description

@JohelEGP

Title: No implicit move or forward on last use in initialization.

Minimal reproducer (https://cpp2.godbolt.org/z/Pb6YaYvsT):

f: (copy x)    = { _ = x; } // OK, moves.
f: (forward x) = { _ = x; } // OK, forwards.
g: (copy x)    = { i := x; } // Wrong, doesn't move.
g: (forward x) = { i := x; } // Wrong, doesn't forward.
main: () = { }
Commands:
cppfront main.cpp2
clang++18 -std=c++23 -stdlib=libc++ -lc++abi -pedantic-errors -Wall -Wextra -Wconversion -Werror=unused-result -I . main.cpp

Expected result:

auto f(auto x) -> void{static_cast<void>(std::move(x));}// OK, moves.
auto f(auto&& x) -> void{static_cast<void>(CPP2_FORWARD(x)); }// OK, forwards.
auto g(auto x) -> void{auto i {std::move(x)}; }// Wrong, doesn't move.
auto g(auto&& x) -> void{auto i {CPP2_FORWARD(x)}; }// Wrong, doesn't forward.

Actual result and error:

Program returned: 0
auto f(auto x) -> void{static_cast<void>(std::move(x));}// OK, moves.
auto f(auto&& x) -> void{static_cast<void>(CPP2_FORWARD(x)); }// OK, forwards.
auto g(auto x) -> void{auto i {x}; }// Wrong, doesn't move.
auto g(auto&& x) -> void{auto i {x}; }// Wrong, doesn't forward.
Cpp2 lowered to Cpp1:
//=== Cpp2 type declarations ====================================================


#include "cpp2util.h"



//=== Cpp2 type definitions and function declarations ===========================

auto f(auto x) -> void;
auto f(auto&& x) -> void;
auto g(auto x) -> void;
auto g(auto&& x) -> void;
auto main() -> int;


//=== Cpp2 function definitions =================================================

auto f(auto x) -> void{static_cast<void>(std::move(x));}// OK, moves.
auto f(auto&& x) -> void{static_cast<void>(CPP2_FORWARD(x)); }// OK, forwards.
auto g(auto x) -> void{auto i {x}; }// Wrong, doesn't move.
auto g(auto&& x) -> void{auto i {x}; }// Wrong, doesn't forward.
auto main() -> int{}

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