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 public:
8   void foo() const;
9 };
10 
11 void capture_by_copy(NonCopyable nc, NonCopyable &ncr) {
12   (void)[nc] { }; // expected-error{{capture of variable 'nc' as type 'NonCopyable' calls private copy constructor}}
13   (void)[=] {
14     ncr.foo(); // expected-error{{capture of variable 'ncr' as type 'NonCopyable' calls private copy constructor}}
15   }();
16 }
17 
18 struct NonTrivial {
19   NonTrivial();
20   NonTrivial(const NonTrivial &);
21   ~NonTrivial();
22 };
23 
24 struct CopyCtorDefault {
25   CopyCtorDefault();
26   CopyCtorDefault(const CopyCtorDefault&, NonTrivial nt = NonTrivial());
27 
28   void foo() const;
29 };
30 
31 void capture_with_default_args(CopyCtorDefault cct) {
32   (void)[=] () -> void { cct.foo(); };
33 }
34 
35 struct ExpectedArrayLayout {
36   CopyCtorDefault array[3];
37 };
38 
39 void capture_array() {
40   CopyCtorDefault array[3];
41   auto x = [=]() -> void {
42     capture(array[0]);
43   };
44   static_assert(sizeof(x) == sizeof(ExpectedArrayLayout), "layout mismatch");
45 }
46 
47 // Check for the expected non-static data members.
48 
49 struct ExpectedLayout {
50   char a;
51   short b;
52 };
53 
54 void test_layout(char a, short b) {
55   auto x = [=] () -> void {
56     capture(a);
57     capture(b);
58   };
59   static_assert(sizeof(x) == sizeof(ExpectedLayout), "Layout mismatch!");
60 }
61 
62 struct ExpectedThisLayout {
63   ExpectedThisLayout* a;
64   void f() {
65     auto x = [this]() -> void {};
66     static_assert(sizeof(x) == sizeof(ExpectedThisLayout), "Layout mismatch!");
67   }
68 };
69