llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.87k stars 11.92k forks source link

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

Open weliveindetail opened 5 months ago

weliveindetail commented 5 months ago
$ 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?

weliveindetail commented 5 months ago

@vgvassilev Is that expected behavior right now, or am I missing sth?

vgvassilev commented 5 months ago

I do not expect that behavior. I expect this to work. We are probably missing some lambda state to push somewhere in Sema.