Closed JohelEGP closed 6 months ago
Title: Move/forward on last use doesn't apply to generated code.
Description:
@union generates set functions with a forward parameter pack. But the lowered code doesn't forward the pack on its last use.
@union
forward
Minimal reproducer (https://cpp2.godbolt.org/z/E9Eq91nEo):
v: @union @print type = { i: int; } main: () = { }
Expected result:
Same as when you copy the @printed code to the Cpp2 source (https://cpp2.godbolt.org/z/fa4T55hGE):
@print
auto v::set_i( auto&& ..._args ) & -> void { if (!(is_i())) { _destroy(); std::construct_at(reinterpret_cast<int*>(&_storage), CPP2_FORWARD(_args)...); } else { *cpp2::assert_not_null(reinterpret_cast<int*>(&_storage)) = int{CPP2_FORWARD(_args)...}; } _discriminator = 0; }
Actual result and error:
No implicit forward on last use in the Cpp1 code lowered from generated Cpp2 code.
auto v::set_i(auto&& ..._args) & -> void{if (!(is_i())) {_destroy();std::construct_at(reinterpret_cast<int*>(&_storage), _args...);}else {*cpp2::assert_not_null(reinterpret_cast<int*>(&_storage)) = int{_args...};}_discriminator = 0;}
See also:
Other bugs in this area:
Title: Move/forward on last use doesn't apply to generated code.
Description:
@union
generates set functions with aforward
parameter pack. But the lowered code doesn't forward the pack on its last use.Minimal reproducer (https://cpp2.godbolt.org/z/E9Eq91nEo):
Commands:
```bash cppfront main.cpp2 clang++18 -std=c++23 -stdlib=libc++ -lc++abi -pedantic-errors -Wall -Wextra -Wconversion -Werror=unused-result -Werror=unused-value -Werror=unused-parameter -I . main.cpp ```Expected result:
Same as when you copy the
@print
ed code to the Cpp2 source (https://cpp2.godbolt.org/z/fa4T55hGE):Actual result and error:
No implicit forward on last use in the Cpp1 code lowered from generated Cpp2 code.
Cpp2 lowered to Cpp1:
```C++ //=== Cpp2 type declarations ==================================================== #include "cpp2util.h" #line 1 "/app/example.cpp2" class v; #line 2 "/app/example.cpp2" //=== Cpp2 type definitions and function declarations =========================== #line 1 "/app/example.cpp2" class v { private: std::aligned_storage_tOutput:
```output Step build returned: 0 [1/3] Generating main.cpp main.cpp2... v: type = { _storage: std::aligned_storage_tSee also:
Other bugs in this area:
857
847
825