blob: 5ee383eebb0241920bfd91e621bfa8d6b86079d0 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 %s -fsyntax-only -verify -fblocks
Steve Naroff1f3b0d52008-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 Lattnerd84aac12010-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 Naroff1f3b0d52008-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 Friedman687abff2009-06-08 04:24:21 +000022 ^(){return 4;}(arg); // expected-error {{too many arguments to block call}}
Steve Naroff1f3b0d52008-09-10 18:33:00 +000023 ^(int x, ...){return 5;}(arg, arg); // Explicit varargs, ok.
24}
25
John McCall13591ed2009-07-25 04:36:53 +000026int main(int argc, char** argv) {
Steve Naroffae530cf2008-09-28 14:02:55 +000027 ^(int argCount) {
28 argCount = 3;
29 }(argc);
30}
Fariborz Jahanian9a66c302010-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 McCallda263792011-02-08 01:59:10 +000037
38// rdar://problem/8962770
39void test4() {
40 int (^f)() = ^((x)) { }; // expected-error {{expected ')'}} expected-warning {{type specifier missing}} expected-note {{to match this}}
41}
42
John McCall4f38f412011-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}