Skip to content

[BUG] Last use of copy/move/forward in for _expression_ not exercised #847

Closed
@JohelEGP

Description

@JohelEGP

Title: Last use of copy/move/forward in for expression not exercised.

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

f: (copy v: std::vector<int>) = { for v do (_) { } } // Doesn't move.
f: (move v: std::vector<int>) = { for v do (_) { } } // Doesn't move.
f: (forward r) = { for r do (_) { } } // 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(std::vector<int> v) -> void{for ( [[maybe_unused]] auto const& unnamed_param_1 : std::move(v) ) {}}// Doesn't move.
#line 2 "/app/example.cpp2"
auto f(std::vector<int>&& v) -> void{for ( [[maybe_unused]] auto const& unnamed_param_1 : std::move(v) ) {}}// Doesn't move.
auto f(auto&& r) -> void{for ( [[maybe_unused]] auto const& unnamed_param_1 : CPP2_FORWARD(r) ) {}}// Doesn't forward.

Actual result and error:

auto f(std::vector<int> v) -> void{for ( [[maybe_unused]] auto const& unnamed_param_1 : v ) {}}// Doesn't move.
#line 2 "/app/example.cpp2"
auto f(std::vector<int>&& v) -> void{for ( [[maybe_unused]] auto const& unnamed_param_1 : v ) {}}// Doesn't move.
auto f(auto&& r) -> void{for ( [[maybe_unused]] auto const& unnamed_param_1 : r ) {}}// Doesn't forward.
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"
auto f(std::vector<int> v) -> void;
#line 2 "/app/example.cpp2"
auto f(std::vector<int>&& v) -> void;
auto f(auto&& r) -> void;
auto main() -> int;

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

#line 1 "/app/example.cpp2"
auto f(std::vector<int> v) -> void{for ( [[maybe_unused]] auto const& unnamed_param_1 : v ) {}}// Doesn't move.
#line 2 "/app/example.cpp2"
auto f(std::vector<int>&& v) -> void{for ( [[maybe_unused]] auto const& unnamed_param_1 : v ) {}}// Doesn't move.
auto f(auto&& r) -> void{for ( [[maybe_unused]] auto const& unnamed_param_1 : r ) {}}// Doesn't forward.
auto main() -> int{}
Output:
Program returned: 0

See also:

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