xref: /llvm-project/clang/test/Sema/block-args.c (revision 0f1c1be1968076d6f96f8a7bcc4a15cf195ecd97)
1 // RUN: %clang_cc1 %s -fsyntax-only -verify -fblocks
2 
3 void take(void*);
4 
test(void)5 void test(void) {
6   take(^(int x){});
7   take(^(int x, int y){});
8   take(^(int x, int y){});
9   take(^(int x,      // expected-note {{previous declaration is here}}
10          int x){});  // expected-error {{redefinition of parameter 'x'}}
11 
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}}
22   ^(){return 4;}(arg); // expected-error {{too many arguments to block call}}
23   ^(int x, ...){return 5;}(arg, arg);   // Explicit varargs, ok.
24 }
25 
main(int argc,char ** argv)26 int main(int argc, char** argv) {
27   ^(int argCount) {
28     argCount = 3;
29   }(argc);
30 }
31 
f0(void)32 void f0(void) {
33   ^(int, double d, char) {}(1, 1.34, 'a'); // expected-warning {{omitting the parameter name in a function definition is a C23 extension}} \
34                                            // expected-warning {{omitting the parameter name in a function definition is a C23 extension}}
35 }
36 
test4(void)37 void test4(void) {
38   int (^f)(void) = ^((x)) { }; // expected-error {{type specifier missing}} expected-error {{type-id cannot have a name}}
39 }
40 
41 void test5_helper(void (^)(int, int[*]));
test5(void)42 void test5(void) {
43   test5_helper(^(int n, int array[n]) {});
44 }
45 
46 // Reduced from a problem on platforms where va_list is an array.
47 struct tag {
48   int x;
49 };
50 typedef struct tag array_ty[1];
test6(void)51 void test6(void) {
52   void (^block)(array_ty) = ^(array_ty arr) { };
53   array_ty arr;
54   block(arr);
55 }
56