1 // RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify 2 3 template<typename T> void capture(const T&); 4 5 class NonCopyable { 6 NonCopyable(const NonCopyable&); // expected-note 2 {{implicitly declared private here}} 7 }; 8 9 void capture_by_copy(NonCopyable nc, NonCopyable &ncr) { 10 // FIXME: error messages should talk about capture 11 (void)[nc] { }; // expected-error{{field of type 'NonCopyable' has private copy constructor}} 12 (void)[ncr] { }; // expected-error{{field of type 'NonCopyable' has private copy constructor}} 13 } 14 15 struct NonTrivial { 16 NonTrivial(); 17 NonTrivial(const NonTrivial &); 18 ~NonTrivial(); 19 }; 20 21 struct CopyCtorDefault { 22 CopyCtorDefault(); 23 CopyCtorDefault(const CopyCtorDefault&, NonTrivial nt = NonTrivial()); 24 25 void foo() const; 26 }; 27 28 void capture_with_default_args(CopyCtorDefault cct) { 29 (void)[=] () -> void { cct.foo(); }; 30 } 31 32 struct ExpectedArrayLayout { 33 CopyCtorDefault array[3]; 34 }; 35 36 void capture_array() { 37 CopyCtorDefault array[3]; 38 auto x = [=]() -> void { 39 capture(array[0]); 40 }; 41 static_assert(sizeof(x) == sizeof(ExpectedArrayLayout), "layout mismatch"); 42 } 43 44 // Check for the expected non-static data members. 45 46 struct ExpectedLayout { 47 char a; 48 short b; 49 }; 50 51 void test_layout(char a, short b) { 52 auto x = [=] () -> void { 53 capture(a); 54 capture(b); 55 }; 56 static_assert(sizeof(x) == sizeof(ExpectedLayout), "Layout mismatch!"); 57 } 58 59 struct ExpectedThisLayout { 60 ExpectedThisLayout* a; 61 void f() { 62 auto x = [this]() -> void {}; 63 static_assert(sizeof(x) == sizeof(ExpectedThisLayout), "Layout mismatch!"); 64 } 65 }; 66