p14.cpp revision b326ca8ffbea96f9cc8a457b0f57be880304a6f5
1// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify
2
3template<typename T> void capture(const T&);
4
5class 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
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}}
13}
14
15struct NonTrivial {
16  NonTrivial();
17  NonTrivial(const NonTrivial &);
18  ~NonTrivial();
19};
20
21struct CopyCtorDefault {
22  CopyCtorDefault();
23  CopyCtorDefault(const CopyCtorDefault&, NonTrivial nt = NonTrivial());
24
25  void foo() const;
26};
27
28void capture_with_default_args(CopyCtorDefault cct) {
29  (void)[=] () -> void { cct.foo(); };
30}
31
32struct ExpectedArrayLayout {
33  CopyCtorDefault array[3];
34};
35
36void capture_array() {
37  CopyCtorDefault array[3];
38  auto x = [=]() -> void {
39    capture(array[0]);
40  };
41  static_assert(sizeof(x) == sizeof(ExpectedArrayLayout), "layout mismatch");
42}
43
44// Check for the expected non-static data members.
45
46struct ExpectedLayout {
47  char a;
48  short b;
49};
50
51void test_layout(char a, short b) {
52  auto x = [=] () -> void {
53    capture(a);
54    capture(b);
55  };
56  static_assert(sizeof(x) == sizeof(ExpectedLayout), "Layout mismatch!");
57}
58