-
Notifications
You must be signed in to change notification settings - Fork 260
[BUG] Last use of copy
/move
/forward
in for _expression_ not exercised
#847
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
When I reported this, I think I was hoping to get a container cleared on move. It uses the variable as an lvalue to access the iterators, so |
Description: Even if the expression isn't just the parameter name, Minimal reproducer (https://cpp2.godbolt.org/z/Tvana63M9):
Commands: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: Move/forward on last use in the expression of the Actual result and error: auto f(std::vector<int> v) -> void{for ( [[maybe_unused]] auto const& unnamed_param_1 : CPP2_UFCS_0(copy, v) ) {}}// Doesn't move.
auto f(std::vector<int>&& v) -> void{for ( [[maybe_unused]] auto const& unnamed_param_1 : CPP2_UFCS_0(copy, v) ) {}}// Doesn't move.
auto f(auto&& r) -> void{for ( [[maybe_unused]] auto const& unnamed_param_1 : CPP2_UFCS_0(copy, r) ) {}}// Doesn't forward.
auto main() -> int{} Cpp2 lowered to Cpp1://=== Cpp2 type declarations ====================================================
#include "cpp2util.h"
#line 1 "/app/example.cpp2"
//=== Cpp2 type definitions and function declarations ===========================
#line 1 "/app/example.cpp2"
[[nodiscard]] auto copy(auto x) -> auto;
#line 2 "/app/example.cpp2"
auto f(std::vector<int> v) -> void;
auto f(std::vector<int>&& v) -> void;
auto f(auto&& r) -> void;
auto main() -> int;
//=== Cpp2 function definitions =================================================
#line 1 "/app/example.cpp2"
[[nodiscard]] auto copy(auto x) -> auto { return std::move(x); }
#line 2 "/app/example.cpp2"
auto f(std::vector<int> v) -> void{for ( [[maybe_unused]] auto const& unnamed_param_1 : CPP2_UFCS_0(copy, v) ) {}}// Doesn't move.
auto f(std::vector<int>&& v) -> void{for ( [[maybe_unused]] auto const& unnamed_param_1 : CPP2_UFCS_0(copy, v) ) {}}// Doesn't move.
auto f(auto&& r) -> void{for ( [[maybe_unused]] auto const& unnamed_param_1 : CPP2_UFCS_0(copy, r) ) {}}// Doesn't forward.
auto main() -> int{} |
The same is true for the loop variable (https://cpp2.godbolt.org/z/KsYen7Y7h):
auto main(int const argc_, char** argv_) -> int{
auto const args = cpp2::make_args(argc_, argv_);
for ( auto x : args ) static_cast<void>(x); // Doesn't move.
for ( auto&& x : args ) static_cast<void>(x); // Doesn't move.
for ( auto&& x : args ) static_cast<void>(x); // Doesn't forward.
} |
Title: Last use of
copy
/move
/forward
in for expression not exercised.Minimal reproducer (https://cpp2.godbolt.org/z/4PE6dTY8f):
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:
Actual result and error:
Cpp2 lowered to Cpp1:
See also:
copy
/forward
parameter not moved/forwarded #825.The text was updated successfully, but these errors were encountered: