Skip to content
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

[BUG] Capture considered local variable #850

Closed
JohelEGP opened this issue Nov 23, 2023 · 0 comments · Fixed by #887
Closed

[BUG] Capture considered local variable #850

JohelEGP opened this issue Nov 23, 2023 · 0 comments · Fixed by #887
Labels
bug Something isn't working

Comments

@JohelEGP
Copy link
Contributor

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:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant