Revert "[llvm] Improve llvm.objectsize computation by computing GEP, alloca and mallo...
[llvm-project.git] / clang / test / CXX / expr / expr.prim / expr.prim.lambda / p14.cpp
blobb570a96a6a0c57f867b54aca07ef578bee131816
1 // RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify
3 template<typename T> void capture(const T&);
5 class NonCopyable {
6 NonCopyable(const NonCopyable&); // expected-note 2 {{implicitly declared private here}}
7 public:
8 void foo() const;
9 };
11 class NonConstCopy {
12 public:
13 NonConstCopy(NonConstCopy&); // expected-note{{would lose const}}
16 void capture_by_copy(NonCopyable nc, NonCopyable &ncr, const NonConstCopy nco) {
17 (void)[nc] { }; // expected-error{{capture of variable 'nc' as type 'NonCopyable' calls private copy constructor}}
18 (void)[=] { // expected-error{{capture of variable 'ncr' as type 'NonCopyable' calls private copy constructor}}
19 ncr.foo();
20 }();
22 [nco] {}(); // expected-error{{no matching constructor for initialization of 'const NonConstCopy'}}
25 struct NonTrivial {
26 NonTrivial();
27 NonTrivial(const NonTrivial &);
28 ~NonTrivial();
31 struct CopyCtorDefault {
32 CopyCtorDefault();
33 CopyCtorDefault(const CopyCtorDefault&, NonTrivial nt = NonTrivial());
35 void foo() const;
38 void capture_with_default_args(CopyCtorDefault cct) {
39 (void)[=] () -> void { cct.foo(); };
42 struct ExpectedArrayLayout {
43 CopyCtorDefault array[3];
46 void capture_array() {
47 CopyCtorDefault array[3];
48 auto x = [=]() -> void {
49 capture(array[0]);
51 static_assert(sizeof(x) == sizeof(ExpectedArrayLayout), "layout mismatch");
54 // Check for the expected non-static data members.
56 struct ExpectedLayout {
57 char a;
58 short b;
61 void test_layout(char a, short b) {
62 auto x = [=] () -> void {
63 capture(a);
64 capture(b);
66 static_assert(sizeof(x) == sizeof(ExpectedLayout), "Layout mismatch!");
69 struct ExpectedThisLayout {
70 ExpectedThisLayout* a;
71 void f() {
72 auto x = [this]() -> void {};
73 static_assert(sizeof(x) == sizeof(ExpectedThisLayout), "Layout mismatch!");
77 struct CaptureArrayAndThis {
78 int value;
80 void f() {
81 int array[3];
82 [=]() -> int {
83 int result = value;
84 for (unsigned i = 0; i < 3; ++i)
85 result += array[i];
86 return result;
87 }();
91 namespace rdar14468891 {
92 class X {
93 public:
94 virtual ~X() = 0; // expected-note{{unimplemented pure virtual method '~X' in 'X'}}
97 class Y : public X { };
99 void capture(X &x) {
100 [x]() {}(); // expected-error{{by-copy capture of value of abstract type 'X'}}
104 namespace rdar15560464 {
105 struct X; // expected-note{{forward declaration of 'rdar15560464::X'}}
106 void foo(const X& param) {
107 auto x = ([=]() {
108 auto& y = param; // expected-error{{by-copy capture of variable 'param' with incomplete type 'const X'}}