1 // RUN: %clang_cc1 -std=c++11 %s -Wunused -verify
2 
3 void odr_used() {
4   int i = 17;
5   [i]{}();
6 }
7 
8 struct ReachingThis {
9   static void static_foo() {
10     (void)[this](){}; // expected-error{{'this' cannot be captured in this context}}
11 
12     struct Local {
13       int i;
14 
15       void bar() {
16         (void)[this](){};
17         (void)[&](){i = 7; };
18       }
19     };
20   }
21 
22   void foo() {
23     (void)[this](){};
24 
25     struct Local {
26       int i;
27 
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 nonstatic data member 'i'}}
31       }
32     };
33   }
34 };
35 
36 void immediately_enclosing(int i) { // expected-note{{'i' declared here}}
37   [i]() {
38     [i] {}();
39   }();
40 
41   [=]() {
42     [i] {}();
43   }();
44 
45   []() { // expected-note{{lambda expression begins here}}
46     [i] {}(); // expected-error{{variable 'i' cannot be implicitly captured in a lambda with no capture-default specified}}
47   }();
48 }
49 
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       // FIXME: We odr-use here, but we shouldn't.
56       //      int x[N][M];
57       //      x[0][0] = i;
58     };
59     (void)N;
60     (void)M;
61     (void)m2;
62   };
63   struct s1 {
64     int f;
65     void work(int n) { // expected-note{{declared here}}
66       int m = n*n;
67       int j = 40; // expected-note{{declared here}}
68       auto m3 = [this,m] { // expected-note 2{{lambda expression begins here}}
69         auto m4 = [&,j] { // expected-error{{variable 'j' cannot be implicitly captured in a lambda with no capture-default specified}}
70           int x = n; // expected-error{{variable 'n' cannot be implicitly captured in a lambda with no capture-default specified}}
71           x += m;
72           x += i; // expected-error{{reference to local variable 'i' declared in enclosing function 'f1'}}
73           x += f;
74         };
75       };
76     }
77   };
78 }
79