Revert "[llvm] Improve llvm.objectsize computation by computing GEP, alloca and mallo...
[llvm-project.git] / clang / test / CXX / expr / expr.prim / expr.prim.lambda / p12.cpp
blob8bc9a1d91cd2c0e4212ccc2edb949a2a5780ba7f
1 // RUN: %clang_cc1 -std=c++11 %s -Wunused -Wno-unused-but-set-variable -Wno-unused-lambda-capture -verify
3 void odr_used() {
4 int i = 17;
5 [i]{}();
8 struct ReachingThis {
9 static void static_foo() {
10 (void)[this](){}; // expected-error{{'this' cannot be captured in this context}}
12 struct Local {
13 int i;
15 void bar() {
16 (void)[this](){};
17 (void)[&](){i = 7; };
22 void foo() {
23 (void)[this](){};
25 struct Local {
26 int i;
28 static void static_bar() {
29 (void)[this](){}; // expected-error{{'this' cannot be captured in this context}}
30 (void)[&](){i = 7; }; // expected-error{{invalid use of member 'i' in static member function}}
36 void immediately_enclosing(int i) { // expected-note{{'i' declared here}}
37 [i]() {
38 [i] {}();
39 }();
41 [=]() {
42 [i] {}();
43 }();
45 []() { // expected-note{{lambda expression begins here}} expected-note 2 {{capture 'i' by}} expected-note 2 {{default capture by}}
46 [i] {}(); // expected-error{{variable 'i' cannot be implicitly captured in a lambda with no capture-default specified}}
47 }();
50 void f1(int i) { // expected-note{{declared here}}
51 int const N = 20;
52 auto m1 = [=]{
53 int const M = 30;
54 auto m2 = [i]{
55 int x[N][M];
56 x[0][0] = i;
57 };
58 (void)N;
59 (void)M;
60 (void)m2;
62 struct s1 {
63 int f;
64 void work(int n) { // expected-note{{declared here}}
65 int m = n*n;
66 int j = 40; // expected-note{{declared here}}
67 auto m3 = [this, m] { // expected-note 3{{lambda expression begins here}} expected-note 2 {{capture 'i' by}} expected-note 2 {{capture 'j' by}} expected-note 2 {{capture 'n' by}}
68 auto m4 = [&,j] { // expected-error{{variable 'j' cannot be implicitly captured in a lambda with no capture-default specified}}
69 int x = n; // expected-error{{variable 'n' cannot be implicitly captured in a lambda with no capture-default specified}}
70 x += m;
71 x += i; // expected-error{{variable 'i' cannot be implicitly captured in a lambda with no capture-default specified}}
72 x += f;