1e31e606fSDouglas Gregor // RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify
2e31e606fSDouglas Gregor 
3199cec76SDouglas Gregor template<typename T> void capture(const T&);
4199cec76SDouglas Gregor 
5e31e606fSDouglas Gregor class NonCopyable {
6e31e606fSDouglas Gregor   NonCopyable(const NonCopyable&); // expected-note 2 {{implicitly declared private here}}
7e31e606fSDouglas Gregor };
8e31e606fSDouglas Gregor 
9e31e606fSDouglas Gregor void capture_by_copy(NonCopyable nc, NonCopyable &ncr) {
10e31e606fSDouglas Gregor   // FIXME: error messages should talk about capture
11656bc62aSDouglas Gregor   (void)[nc] { }; // expected-error{{field of type 'NonCopyable' has private copy constructor}}
12656bc62aSDouglas Gregor   (void)[ncr] { }; // expected-error{{field of type 'NonCopyable' has private copy constructor}}
13e31e606fSDouglas Gregor }
14e31e606fSDouglas Gregor 
158c50e7c5SDouglas Gregor struct NonTrivial {
168c50e7c5SDouglas Gregor   NonTrivial();
178c50e7c5SDouglas Gregor   NonTrivial(const NonTrivial &);
188c50e7c5SDouglas Gregor   ~NonTrivial();
198c50e7c5SDouglas Gregor };
208c50e7c5SDouglas Gregor 
218c50e7c5SDouglas Gregor struct CopyCtorDefault {
22199cec76SDouglas Gregor   CopyCtorDefault();
238c50e7c5SDouglas Gregor   CopyCtorDefault(const CopyCtorDefault&, NonTrivial nt = NonTrivial());
248c50e7c5SDouglas Gregor 
258c50e7c5SDouglas Gregor   void foo() const;
268c50e7c5SDouglas Gregor };
278c50e7c5SDouglas Gregor 
288c50e7c5SDouglas Gregor void capture_with_default_args(CopyCtorDefault cct) {
29656bc62aSDouglas Gregor   (void)[=] () -> void { cct.foo(); };
308c50e7c5SDouglas Gregor }
318c50e7c5SDouglas Gregor 
32199cec76SDouglas Gregor struct ExpectedArrayLayout {
33199cec76SDouglas Gregor   CopyCtorDefault array[3];
34199cec76SDouglas Gregor };
35199cec76SDouglas Gregor 
36199cec76SDouglas Gregor void capture_array() {
37199cec76SDouglas Gregor   CopyCtorDefault array[3];
38656bc62aSDouglas Gregor   auto x = [=]() -> void {
39199cec76SDouglas Gregor     capture(array[0]);
40199cec76SDouglas Gregor   };
41199cec76SDouglas Gregor   static_assert(sizeof(x) == sizeof(ExpectedArrayLayout), "layout mismatch");
42199cec76SDouglas Gregor }
433d23f788SDouglas Gregor 
443d23f788SDouglas Gregor // Check for the expected non-static data members.
453d23f788SDouglas Gregor 
463d23f788SDouglas Gregor struct ExpectedLayout {
473d23f788SDouglas Gregor   char a;
483d23f788SDouglas Gregor   short b;
493d23f788SDouglas Gregor };
503d23f788SDouglas Gregor 
513d23f788SDouglas Gregor void test_layout(char a, short b) {
52656bc62aSDouglas Gregor   auto x = [=] () -> void {
533d23f788SDouglas Gregor     capture(a);
543d23f788SDouglas Gregor     capture(b);
553d23f788SDouglas Gregor   };
563d23f788SDouglas Gregor   static_assert(sizeof(x) == sizeof(ExpectedLayout), "Layout mismatch!");
573d23f788SDouglas Gregor }
58*c9751069SEli Friedman 
59*c9751069SEli Friedman struct ExpectedThisLayout {
60*c9751069SEli Friedman   ExpectedThisLayout* a;
61*c9751069SEli Friedman   void f() {
62*c9751069SEli Friedman     auto x = [this]() -> void {};
63*c9751069SEli Friedman     static_assert(sizeof(x) == sizeof(ExpectedThisLayout), "Layout mismatch!");
64*c9751069SEli Friedman   }
65*c9751069SEli Friedman };
66