1 // RUN: %clang_cc1 -triple i686-pc-linux -std=c++11 -fblocks %s -verify
3 void block_capture_errors() {
4 __block int var; // expected-note 2{{'var' declared here}}
5 (void)[var] { }; // expected-error{{__block variable 'var' cannot be captured in a lambda}}
7 (void)[=] { var = 17; }; // expected-error{{__block variable 'var' cannot be captured in a lambda}}
10 void conversion_to_block(int captured) {
11 int (^b1)(int) = [=](int x) { return x + captured; };
13 const auto lambda = [=](int x) { return x + captured; };
14 int (^b2)(int) = lambda;
18 class ConstCopyConstructorBoom {
20 ConstCopyConstructorBoom(ConstCopyConstructorBoom&);
22 ConstCopyConstructorBoom(const ConstCopyConstructorBoom&) {
23 T *ptr = 1; // expected-error{{cannot initialize a variable of type 'float *' with an rvalue of type 'int'}}
29 void conversion_to_block_init(ConstCopyConstructorBoom<int> boom,
30 ConstCopyConstructorBoom<float> boom2) {
31 const auto& lambda1([=] { boom.foo(); }); // okay
33 const auto& lambda2([=] { boom2.foo(); }); // expected-note{{in instantiation of member function}}
34 void (^block)(void) = lambda2;
39 int array[7]; // expected-note 2{{'array' declared here}}
52 int i = array[2]; // expected-error{{cannot refer to declaration with an array type inside block}}
60 i += array[3]; // expected-error{{cannot refer to declaration with an array type inside block}}
66 namespace overloading {
67 void bool_conversion() {
76 int (*fp)(int) = [](int x) { return x + 1; };
77 fp = [](int x) { return x + 1; };
79 typedef int (*func_ptr)(int);
80 fp = (func_ptr)[](int x) { return x + 1; };
82 int (^bp)(int) = [](int x) { return x + 1; };
83 bp = [](int x) { return x + 1; };
85 typedef int (^block_ptr)(int);
86 bp = (block_ptr)[](int x) { return x + 1; };
89 int &accept_lambda_conv(int (*fp)(int));
90 float &accept_lambda_conv(int (^bp)(int));
92 void call_with_lambda() {
93 int &ir = accept_lambda_conv([](int x) { return x + 1; });
96 template<typename T> using id = T;
99 struct C : decltype(a) {
100 using decltype(a)::operator id<void(*)()>;
102 using decltype(a)::operator id<void(^)()>;
105 struct D : decltype(a) {
106 using decltype(a)::operator id<void(^)()>;
108 using decltype(a)::operator id<void(*)()>; // expected-note {{here}}
112 bool r2 = d; // expected-error {{private}}
117 template<typename ... Args> static void f(Args...);
119 template<typename ... Args> static void f1()
121 (void)^(Args args) { // expected-error{{block contains unexpanded parameter pack 'Args'}}
125 template<typename ... Args> static void f2()
127 // FIXME: Allow this.
129 ^(Args args) // expected-error{{block contains unexpanded parameter pack 'Args'}}
131 ... // expected-error{{pack expansion does not contain any unexpanded parameter packs}}
135 template<typename ... Args> static void f3()
137 (void)[](Args args) { // expected-error{{expression contains unexpanded parameter pack 'Args'}}
141 template<typename ... Args> static void f4()
143 f([](Args args) { } ...);