llvm / llvm-project

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

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

Open weliveindetail opened 1 month ago

weliveindetail commented 1 month 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 1 month ago

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

vgvassilev commented 1 month ago

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