blob: ad603e17193dc9097b2c6c7aa03a81921b9d295b [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}}
7};
8
9void capture_by_copy(NonCopyable nc, NonCopyable &ncr) {
10 // FIXME: error messages should talk about capture
Douglas Gregor656bc622012-02-09 08:26:42 +000011 (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 Gregore31e6062012-02-07 10:09:13 +000013}
14
Douglas Gregor8c50e7c2012-02-09 00:47:04 +000015struct NonTrivial {
16 NonTrivial();
17 NonTrivial(const NonTrivial &);
18 ~NonTrivial();
19};
20
21struct CopyCtorDefault {
Douglas Gregor199cec72012-02-09 02:45:47 +000022 CopyCtorDefault();
Douglas Gregor8c50e7c2012-02-09 00:47:04 +000023 CopyCtorDefault(const CopyCtorDefault&, NonTrivial nt = NonTrivial());
24
25 void foo() const;
26};
27
28void capture_with_default_args(CopyCtorDefault cct) {
Douglas Gregor656bc622012-02-09 08:26:42 +000029 (void)[=] () -> void { cct.foo(); };
Douglas Gregor8c50e7c2012-02-09 00:47:04 +000030}
31
Douglas Gregor199cec72012-02-09 02:45:47 +000032struct ExpectedArrayLayout {
33 CopyCtorDefault array[3];
34};
35
36void capture_array() {
37 CopyCtorDefault array[3];
Douglas Gregor656bc622012-02-09 08:26:42 +000038 auto x = [=]() -> void {
Douglas Gregor199cec72012-02-09 02:45:47 +000039 capture(array[0]);
40 };
41 static_assert(sizeof(x) == sizeof(ExpectedArrayLayout), "layout mismatch");
42}
Douglas Gregor3d23f7882012-02-09 02:12:34 +000043
44// Check for the expected non-static data members.
45
46struct ExpectedLayout {
47 char a;
48 short b;
49};
50
Douglas Gregor3d23f7882012-02-09 02:12:34 +000051void test_layout(char a, short b) {
Douglas Gregor656bc622012-02-09 08:26:42 +000052 auto x = [=] () -> void {
Douglas Gregor3d23f7882012-02-09 02:12:34 +000053 capture(a);
54 capture(b);
55 };
56 static_assert(sizeof(x) == sizeof(ExpectedLayout), "Layout mismatch!");
57}