p14.cpp revision 668165ab1e604b063c0aa0df8ff91c80879670bf
1// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify 2 3template<typename T> void capture(const T&); 4 5class NonCopyable { 6 NonCopyable(const NonCopyable&); // expected-note 2 {{implicitly declared private here}} 7}; 8 9void 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 15struct NonTrivial { 16 NonTrivial(); 17 NonTrivial(const NonTrivial &); 18 ~NonTrivial(); 19}; 20 21struct CopyCtorDefault { 22 CopyCtorDefault(); 23 CopyCtorDefault(const CopyCtorDefault&, NonTrivial nt = NonTrivial()); 24 25 void foo() const; 26}; 27 28void capture_with_default_args(CopyCtorDefault cct) { 29 (void)[=] () -> void { cct.foo(); }; 30} 31 32struct ExpectedArrayLayout { 33 CopyCtorDefault array[3]; 34}; 35 36void 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 46struct ExpectedLayout { 47 char a; 48 short b; 49}; 50 51void 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 59struct ExpectedThisLayout { 60 ExpectedThisLayout* a; 61 void f() { 62 auto x = [this]() -> void {}; 63 static_assert(sizeof(x) == sizeof(ExpectedThisLayout), "Layout mismatch!"); 64 } 65}; 66