Closed
Description
Title: Capture considered local variable.
Description:
This is the example in the commit message of commit 4bd0c04.
But with a compound block instead.
Minimal reproducer (https://cpp2.godbolt.org/z/YTjP69cxP):
main: () = {
v: std::vector = ( 1, 2, 3, 4, 5 );
// Definite last use of v => move-capture v into f's closure
f := :() -> forward _ = { return v$; };
// Now we can access the vector captured inside f()...
f().push_back(6);
for f() do(e) std::cout << e; // prints 123456
}
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: Same as with f := :() -> forward _ = v$;
.
Actual result and error: main.cpp2(5,31): error: a 'forward' return type cannot return a local variable
.
See also: