Debian Codegraph @

clang/test/Interpreter/lambda.cpp

raw
1 // REQUIRES: host-supports-jit
2 // RUN: cat %s | clang-repl | FileCheck %s
3 // At -O2, somehow "x = 42" appears first when piped into FileCheck,
4 // see https://github.com/llvm/llvm-project/issues/143547.
5 // RUN: %if !system-windows %{ cat %s | clang-repl -Xcc -Xclang -Xcc -verify -Xcc -O2 | FileCheck %s %}
6
7 extern "C" int printf(const char *, ...);
8
9 auto l1 = []() { printf("ONE\n"); return 42; };
10 auto l2 = []() { printf("TWO\n"); return 17; };
11
12 auto r1 = l1();
13 // CHECK: ONE
14 auto r2 = l2();
15 // CHECK: TWO
16 auto r3 = l2();
17 // CHECK: TWO
18
19 // Verify non-local lambda capture error is correctly reported
20 int x = 42;
21
22 // expected-error {{non-local lambda expression cannot have a capture-default}}
23 auto capture = [&]() { return x * 2; };
24
25 // Ensure interpreter continues and x is still valid
26 printf("x = %d\n", x);
27 // CHECK: x = 42
28
29 %quit