p12.cpp revision 73d90928c0462daf0665fd7f8e44ca00d896540d
1// RUN: %clang_cc1 -std=c++11 %s -Wunused -verify 2 3void odr_used() { 4 int i = 17; 5 [i]{}(); 6} 7 8struct 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 36void 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