blob: 69cf047a9ecef9a5920d7252d8479d0cf8e26084 [file] [log] [blame]
Daniel Dunbar8fbe78f2009-12-15 20:14:24 +00001// RUN: %clang_cc1 %s -fsyntax-only -verify -fblocks
Steve Naroff3ef15b52008-09-10 18:33:00 +00002
3void take(void*);
4
5void test() {
6 take(^(int x){});
7 take(^(int x, int y){});
8 take(^(int x, int y){});
Chris Lattnerdd1cb5b2010-02-22 00:40:25 +00009 take(^(int x, // expected-note {{previous declaration is here}}
10 int x){}); // expected-error {{redefinition of parameter 'x'}}
Steve Naroff3ef15b52008-09-10 18:33:00 +000011
12
13 take(^(int x) { return x+1; });
14
15 int (^CP)(int) = ^(int x) { return x*x; };
16 take(CP);
17
18 int arg;
19 ^{return 1;}();
20 ^{return 2;}(arg); // expected-error {{too many arguments to block call}}
21 ^(void){return 3;}(1); // expected-error {{too many arguments to block call}}
Eli Friedman9e81b022009-06-08 04:24:21 +000022 ^(){return 4;}(arg); // expected-error {{too many arguments to block call}}
Steve Naroff3ef15b52008-09-10 18:33:00 +000023 ^(int x, ...){return 5;}(arg, arg); // Explicit varargs, ok.
24}
25
John McCall02dee0a2009-07-25 04:36:53 +000026int main(int argc, char** argv) {
Steve Naroff4831c742008-09-28 14:02:55 +000027 ^(int argCount) {
28 argCount = 3;
29 }(argc);
30}
Fariborz Jahanian5ec502e2010-02-12 21:53:14 +000031
32// radar 7528255
33void f0() {
34 ^(int, double d, char) {}(1, 1.34, 'a'); // expected-error {{parameter name omitted}} \
35 // expected-error {{parameter name omitted}}
36}
John McCall653dac42011-02-08 01:59:10 +000037
38// rdar://problem/8962770
39void test4() {
Richard Smith74639b12017-05-19 01:54:59 +000040 int (^f)() = ^((x)) { }; // expected-warning {{type specifier missing}} expected-error {{type-id cannot have a name}}
John McCall653dac42011-02-08 01:59:10 +000041}
42
John McCall92d627e2011-03-22 23:15:50 +000043// rdar://problem/9170609
44void test5_helper(void (^)(int, int[*]));
45void test5(void) {
46 test5_helper(^(int n, int array[n]) {});
47}
Reid Kleckner88709c62013-06-08 18:51:21 +000048
49// Reduced from a problem on platforms where va_list is an array.
50struct tag {
51 int x;
52};
53typedef struct tag array_ty[1];
54void test6(void) {
55 void (^block)(array_ty) = ^(array_ty arr) { };
56 array_ty arr;
57 block(arr);
58}