blob: e99130fcd638ddfa4631f95b40066e09d0acdd36 [file] [log] [blame]
Douglas Gregore31e6062012-02-07 10:09:13 +00001// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify
2
Douglas Gregor199cec72012-02-09 02:45:47 +00003template<typename T> void capture(const T&);
4
Douglas Gregore31e6062012-02-07 10:09:13 +00005class NonCopyable {
6 NonCopyable(const NonCopyable&); // expected-note 2 {{implicitly declared private here}}
Douglas Gregor19666fb2012-02-15 16:57:26 +00007public:
8 void foo() const;
Douglas Gregore31e6062012-02-07 10:09:13 +00009};
10
11void capture_by_copy(NonCopyable nc, NonCopyable &ncr) {
Douglas Gregor19666fb2012-02-15 16:57:26 +000012 (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 }();
Douglas Gregore31e6062012-02-07 10:09:13 +000016}
17
Douglas Gregor8c50e7c2012-02-09 00:47:04 +000018struct NonTrivial {
19 NonTrivial();
20 NonTrivial(const NonTrivial &);
21 ~NonTrivial();
22};
23
24struct CopyCtorDefault {
Douglas Gregor199cec72012-02-09 02:45:47 +000025 CopyCtorDefault();
Douglas Gregor8c50e7c2012-02-09 00:47:04 +000026 CopyCtorDefault(const CopyCtorDefault&, NonTrivial nt = NonTrivial());
27
28 void foo() const;
29};
30
31void capture_with_default_args(CopyCtorDefault cct) {
Douglas Gregor656bc622012-02-09 08:26:42 +000032 (void)[=] () -> void { cct.foo(); };
Douglas Gregor8c50e7c2012-02-09 00:47:04 +000033}
34
Douglas Gregor199cec72012-02-09 02:45:47 +000035struct ExpectedArrayLayout {
36 CopyCtorDefault array[3];
37};
38
39void capture_array() {
40 CopyCtorDefault array[3];
Douglas Gregor656bc622012-02-09 08:26:42 +000041 auto x = [=]() -> void {
Douglas Gregor199cec72012-02-09 02:45:47 +000042 capture(array[0]);
43 };
44 static_assert(sizeof(x) == sizeof(ExpectedArrayLayout), "layout mismatch");
45}
Douglas Gregor3d23f7882012-02-09 02:12:34 +000046
47// Check for the expected non-static data members.
48
49struct ExpectedLayout {
50 char a;
51 short b;
52};
53
Douglas Gregor3d23f7882012-02-09 02:12:34 +000054void test_layout(char a, short b) {
Douglas Gregor656bc622012-02-09 08:26:42 +000055 auto x = [=] () -> void {
Douglas Gregor3d23f7882012-02-09 02:12:34 +000056 capture(a);
57 capture(b);
58 };
59 static_assert(sizeof(x) == sizeof(ExpectedLayout), "Layout mismatch!");
60}
Eli Friedmanc9751062012-02-11 02:51:16 +000061
62struct ExpectedThisLayout {
63 ExpectedThisLayout* a;
64 void f() {
65 auto x = [this]() -> void {};
66 static_assert(sizeof(x) == sizeof(ExpectedThisLayout), "Layout mismatch!");
67 }
68};