Skip to content

[clang-repl] Lambda capture not working? #92112

@weliveindetail

Description

@weliveindetail
$ bin/clang-repl
clang-repl> int state = 0;
clang-repl> auto toggle = [&]() { return state; };
In file included from <<< inputs >>>:1:
input_line_2:1:16: error: non-local lambda expression cannot have a capture-default
    1 | auto toggle = [&]() { return state; };
      |                ^
error: Parsing failed.
clang-repl> auto toggle = [&state]() { return state; };
input_line_3:1:17: error: 'state' cannot be captured because it does not have automatic storage duration
    1 | auto toggle = [&state]() { return state; };
      |                 ^
input_line_1:1:5: note: 'state' declared here
    1 | int state = 0;
      |     ^
error: Parsing failed.

Is this expected behavior on current mainline?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions