xref: /minix3/external/bsd/llvm/dist/clang/test/Sema/block-args.c (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 %s -fsyntax-only -verify -fblocks
2*f4a2713aSLionel Sambuc 
3*f4a2713aSLionel Sambuc void take(void*);
4*f4a2713aSLionel Sambuc 
test()5*f4a2713aSLionel Sambuc void test() {
6*f4a2713aSLionel Sambuc   take(^(int x){});
7*f4a2713aSLionel Sambuc   take(^(int x, int y){});
8*f4a2713aSLionel Sambuc   take(^(int x, int y){});
9*f4a2713aSLionel Sambuc   take(^(int x,      // expected-note {{previous declaration is here}}
10*f4a2713aSLionel Sambuc          int x){});  // expected-error {{redefinition of parameter 'x'}}
11*f4a2713aSLionel Sambuc 
12*f4a2713aSLionel Sambuc 
13*f4a2713aSLionel Sambuc   take(^(int x) { return x+1; });
14*f4a2713aSLionel Sambuc 
15*f4a2713aSLionel Sambuc   int (^CP)(int) = ^(int x) { return x*x; };
16*f4a2713aSLionel Sambuc   take(CP);
17*f4a2713aSLionel Sambuc 
18*f4a2713aSLionel Sambuc   int arg;
19*f4a2713aSLionel Sambuc   ^{return 1;}();
20*f4a2713aSLionel Sambuc   ^{return 2;}(arg); // expected-error {{too many arguments to block call}}
21*f4a2713aSLionel Sambuc   ^(void){return 3;}(1); // expected-error {{too many arguments to block call}}
22*f4a2713aSLionel Sambuc   ^(){return 4;}(arg); // expected-error {{too many arguments to block call}}
23*f4a2713aSLionel Sambuc   ^(int x, ...){return 5;}(arg, arg);   // Explicit varargs, ok.
24*f4a2713aSLionel Sambuc }
25*f4a2713aSLionel Sambuc 
main(int argc,char ** argv)26*f4a2713aSLionel Sambuc int main(int argc, char** argv) {
27*f4a2713aSLionel Sambuc   ^(int argCount) {
28*f4a2713aSLionel Sambuc     argCount = 3;
29*f4a2713aSLionel Sambuc   }(argc);
30*f4a2713aSLionel Sambuc }
31*f4a2713aSLionel Sambuc 
32*f4a2713aSLionel Sambuc // radar 7528255
f0()33*f4a2713aSLionel Sambuc void f0() {
34*f4a2713aSLionel Sambuc   ^(int, double d, char) {}(1, 1.34, 'a'); // expected-error {{parameter name omitted}} \
35*f4a2713aSLionel Sambuc 				 	   // expected-error {{parameter name omitted}}
36*f4a2713aSLionel Sambuc }
37*f4a2713aSLionel Sambuc 
38*f4a2713aSLionel Sambuc // rdar://problem/8962770
test4()39*f4a2713aSLionel Sambuc void test4() {
40*f4a2713aSLionel Sambuc   int (^f)() = ^((x)) { }; // expected-error {{expected ')'}} expected-warning {{type specifier missing}} expected-note {{to match this}}
41*f4a2713aSLionel Sambuc }
42*f4a2713aSLionel Sambuc 
43*f4a2713aSLionel Sambuc // rdar://problem/9170609
44*f4a2713aSLionel Sambuc void test5_helper(void (^)(int, int[*]));
test5(void)45*f4a2713aSLionel Sambuc void test5(void) {
46*f4a2713aSLionel Sambuc   test5_helper(^(int n, int array[n]) {});
47*f4a2713aSLionel Sambuc }
48*f4a2713aSLionel Sambuc 
49*f4a2713aSLionel Sambuc // Reduced from a problem on platforms where va_list is an array.
50*f4a2713aSLionel Sambuc struct tag {
51*f4a2713aSLionel Sambuc   int x;
52*f4a2713aSLionel Sambuc };
53*f4a2713aSLionel Sambuc typedef struct tag array_ty[1];
test6(void)54*f4a2713aSLionel Sambuc void test6(void) {
55*f4a2713aSLionel Sambuc   void (^block)(array_ty) = ^(array_ty arr) { };
56*f4a2713aSLionel Sambuc   array_ty arr;
57*f4a2713aSLionel Sambuc   block(arr);
58*f4a2713aSLionel Sambuc }
59