| Douglas Gregor | e31e606 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify | 
|  | 2 |  | 
| Douglas Gregor | 199cec7 | 2012-02-09 02:45:47 +0000 | [diff] [blame] | 3 | template<typename T> void capture(const T&); | 
|  | 4 |  | 
| Douglas Gregor | e31e606 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 5 | class NonCopyable { | 
|  | 6 | NonCopyable(const NonCopyable&); // expected-note 2 {{implicitly declared private here}} | 
| Douglas Gregor | 19666fb | 2012-02-15 16:57:26 +0000 | [diff] [blame] | 7 | public: | 
|  | 8 | void foo() const; | 
| Douglas Gregor | e31e606 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 9 | }; | 
|  | 10 |  | 
| Douglas Gregor | 02267a8 | 2012-02-15 17:05:32 +0000 | [diff] [blame] | 11 | class NonConstCopy { | 
|  | 12 | public: | 
|  | 13 | NonConstCopy(NonConstCopy&); // expected-note{{would lose const}} | 
|  | 14 | }; | 
|  | 15 |  | 
|  | 16 | void capture_by_copy(NonCopyable nc, NonCopyable &ncr, const NonConstCopy nco) { | 
| Douglas Gregor | 19666fb | 2012-02-15 16:57:26 +0000 | [diff] [blame] | 17 | (void)[nc] { }; // expected-error{{capture of variable 'nc' as type 'NonCopyable' calls private copy constructor}} | 
|  | 18 | (void)[=] { | 
|  | 19 | ncr.foo(); // expected-error{{capture of variable 'ncr' as type 'NonCopyable' calls private copy constructor}} | 
|  | 20 | }(); | 
| Douglas Gregor | 02267a8 | 2012-02-15 17:05:32 +0000 | [diff] [blame] | 21 |  | 
|  | 22 | [nco] {}(); // expected-error{{no matching constructor for initialization of 'const NonConstCopy'}} | 
| Douglas Gregor | e31e606 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 23 | } | 
|  | 24 |  | 
| Douglas Gregor | 8c50e7c | 2012-02-09 00:47:04 +0000 | [diff] [blame] | 25 | struct NonTrivial { | 
|  | 26 | NonTrivial(); | 
|  | 27 | NonTrivial(const NonTrivial &); | 
|  | 28 | ~NonTrivial(); | 
|  | 29 | }; | 
|  | 30 |  | 
|  | 31 | struct CopyCtorDefault { | 
| Douglas Gregor | 199cec7 | 2012-02-09 02:45:47 +0000 | [diff] [blame] | 32 | CopyCtorDefault(); | 
| Douglas Gregor | 8c50e7c | 2012-02-09 00:47:04 +0000 | [diff] [blame] | 33 | CopyCtorDefault(const CopyCtorDefault&, NonTrivial nt = NonTrivial()); | 
|  | 34 |  | 
|  | 35 | void foo() const; | 
|  | 36 | }; | 
|  | 37 |  | 
|  | 38 | void capture_with_default_args(CopyCtorDefault cct) { | 
| Douglas Gregor | 656bc62 | 2012-02-09 08:26:42 +0000 | [diff] [blame] | 39 | (void)[=] () -> void { cct.foo(); }; | 
| Douglas Gregor | 8c50e7c | 2012-02-09 00:47:04 +0000 | [diff] [blame] | 40 | } | 
|  | 41 |  | 
| Douglas Gregor | 199cec7 | 2012-02-09 02:45:47 +0000 | [diff] [blame] | 42 | struct ExpectedArrayLayout { | 
|  | 43 | CopyCtorDefault array[3]; | 
|  | 44 | }; | 
|  | 45 |  | 
|  | 46 | void capture_array() { | 
|  | 47 | CopyCtorDefault array[3]; | 
| Douglas Gregor | 656bc62 | 2012-02-09 08:26:42 +0000 | [diff] [blame] | 48 | auto x = [=]() -> void { | 
| Douglas Gregor | 199cec7 | 2012-02-09 02:45:47 +0000 | [diff] [blame] | 49 | capture(array[0]); | 
|  | 50 | }; | 
|  | 51 | static_assert(sizeof(x) == sizeof(ExpectedArrayLayout), "layout mismatch"); | 
|  | 52 | } | 
| Douglas Gregor | 3d23f788 | 2012-02-09 02:12:34 +0000 | [diff] [blame] | 53 |  | 
|  | 54 | // Check for the expected non-static data members. | 
|  | 55 |  | 
|  | 56 | struct ExpectedLayout { | 
|  | 57 | char a; | 
|  | 58 | short b; | 
|  | 59 | }; | 
|  | 60 |  | 
| Douglas Gregor | 3d23f788 | 2012-02-09 02:12:34 +0000 | [diff] [blame] | 61 | void test_layout(char a, short b) { | 
| Douglas Gregor | 656bc62 | 2012-02-09 08:26:42 +0000 | [diff] [blame] | 62 | auto x = [=] () -> void { | 
| Douglas Gregor | 3d23f788 | 2012-02-09 02:12:34 +0000 | [diff] [blame] | 63 | capture(a); | 
|  | 64 | capture(b); | 
|  | 65 | }; | 
|  | 66 | static_assert(sizeof(x) == sizeof(ExpectedLayout), "Layout mismatch!"); | 
|  | 67 | } | 
| Eli Friedman | c975106 | 2012-02-11 02:51:16 +0000 | [diff] [blame] | 68 |  | 
|  | 69 | struct ExpectedThisLayout { | 
|  | 70 | ExpectedThisLayout* a; | 
|  | 71 | void f() { | 
|  | 72 | auto x = [this]() -> void {}; | 
|  | 73 | static_assert(sizeof(x) == sizeof(ExpectedThisLayout), "Layout mismatch!"); | 
|  | 74 | } | 
|  | 75 | }; |