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}} |
| 7 | }; |
| 8 | |
| 9 | void capture_by_copy(NonCopyable nc, NonCopyable &ncr) { |
| 10 | // FIXME: error messages should talk about capture |
Douglas Gregor | 656bc62 | 2012-02-09 08:26:42 +0000 | [diff] [blame^] | 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}} |
Douglas Gregor | e31e606 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 13 | } |
| 14 | |
Douglas Gregor | 8c50e7c | 2012-02-09 00:47:04 +0000 | [diff] [blame] | 15 | struct NonTrivial { |
| 16 | NonTrivial(); |
| 17 | NonTrivial(const NonTrivial &); |
| 18 | ~NonTrivial(); |
| 19 | }; |
| 20 | |
| 21 | struct CopyCtorDefault { |
Douglas Gregor | 199cec7 | 2012-02-09 02:45:47 +0000 | [diff] [blame] | 22 | CopyCtorDefault(); |
Douglas Gregor | 8c50e7c | 2012-02-09 00:47:04 +0000 | [diff] [blame] | 23 | CopyCtorDefault(const CopyCtorDefault&, NonTrivial nt = NonTrivial()); |
| 24 | |
| 25 | void foo() const; |
| 26 | }; |
| 27 | |
| 28 | void capture_with_default_args(CopyCtorDefault cct) { |
Douglas Gregor | 656bc62 | 2012-02-09 08:26:42 +0000 | [diff] [blame^] | 29 | (void)[=] () -> void { cct.foo(); }; |
Douglas Gregor | 8c50e7c | 2012-02-09 00:47:04 +0000 | [diff] [blame] | 30 | } |
| 31 | |
Douglas Gregor | 199cec7 | 2012-02-09 02:45:47 +0000 | [diff] [blame] | 32 | struct ExpectedArrayLayout { |
| 33 | CopyCtorDefault array[3]; |
| 34 | }; |
| 35 | |
| 36 | void capture_array() { |
| 37 | CopyCtorDefault array[3]; |
Douglas Gregor | 656bc62 | 2012-02-09 08:26:42 +0000 | [diff] [blame^] | 38 | auto x = [=]() -> void { |
Douglas Gregor | 199cec7 | 2012-02-09 02:45:47 +0000 | [diff] [blame] | 39 | capture(array[0]); |
| 40 | }; |
| 41 | static_assert(sizeof(x) == sizeof(ExpectedArrayLayout), "layout mismatch"); |
| 42 | } |
Douglas Gregor | 3d23f788 | 2012-02-09 02:12:34 +0000 | [diff] [blame] | 43 | |
| 44 | // Check for the expected non-static data members. |
| 45 | |
| 46 | struct ExpectedLayout { |
| 47 | char a; |
| 48 | short b; |
| 49 | }; |
| 50 | |
Douglas Gregor | 3d23f788 | 2012-02-09 02:12:34 +0000 | [diff] [blame] | 51 | void test_layout(char a, short b) { |
Douglas Gregor | 656bc62 | 2012-02-09 08:26:42 +0000 | [diff] [blame^] | 52 | auto x = [=] () -> void { |
Douglas Gregor | 3d23f788 | 2012-02-09 02:12:34 +0000 | [diff] [blame] | 53 | capture(a); |
| 54 | capture(b); |
| 55 | }; |
| 56 | static_assert(sizeof(x) == sizeof(ExpectedLayout), "Layout mismatch!"); |
| 57 | } |