30 lines · cpp
1// REQUIRES: host-supports-jit2// RUN: cat %s | clang-repl | FileCheck %s3// 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 7extern "C" int printf(const char *, ...);8 9auto l1 = []() { printf("ONE\n"); return 42; };10auto l2 = []() { printf("TWO\n"); return 17; };11 12auto r1 = l1();13// CHECK: ONE14auto r2 = l2();15// CHECK: TWO16auto r3 = l2();17// CHECK: TWO18 19// Verify non-local lambda capture error is correctly reported20int x = 42;21 22// expected-error {{non-local lambda expression cannot have a capture-default}}23auto capture = [&]() { return x * 2; };24 25// Ensure interpreter continues and x is still valid26printf("x = %d\n", x);27// CHECK: x = 4228 29%quit30