blob: e9c2341a99c756b93ee23739b46f45c32f0639b8 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only %s -verify -fblocks
Steve Naroff61f40a22008-09-10 19:17:48 +00002
3void I( void (^)(void));
4void (^noop)(void);
5
6void nothing();
7int printf(const char*, ...);
8
9typedef void (^T) (void);
10
Mike Stump0e88b162009-08-27 00:29:21 +000011void takeblock(T);
Steve Naroff61f40a22008-09-10 19:17:48 +000012int takeintint(int (^C)(int)) { return C(4); }
13
14T somefunction() {
Mike Stump1eb44332009-09-09 15:08:12 +000015 if (^{ })
16 nothing();
Steve Naroff61f40a22008-09-10 19:17:48 +000017
Mike Stump1eb44332009-09-09 15:08:12 +000018 noop = ^{};
Steve Naroff61f40a22008-09-10 19:17:48 +000019
Mike Stump1eb44332009-09-09 15:08:12 +000020 noop = ^{printf("\nClosure\n"); };
Steve Naroff61f40a22008-09-10 19:17:48 +000021
Mike Stump1eb44332009-09-09 15:08:12 +000022 I(^{ });
Steve Naroff61f40a22008-09-10 19:17:48 +000023
Mike Stump1eb44332009-09-09 15:08:12 +000024 return ^{printf("\nClosure\n"); };
Steve Naroff61f40a22008-09-10 19:17:48 +000025}
26void test2() {
Mike Stump1eb44332009-09-09 15:08:12 +000027 int x = 4;
Steve Naroff61f40a22008-09-10 19:17:48 +000028
Mike Stump1eb44332009-09-09 15:08:12 +000029 takeblock(^{ printf("%d\n", x); });
Steve Naroff61f40a22008-09-10 19:17:48 +000030
31 while (1) {
Mike Stump1eb44332009-09-09 15:08:12 +000032 takeblock(^{
33 break; // expected-error {{'break' statement not in loop or switch statement}}
34 continue; // expected-error {{'continue' statement not in loop statement}}
35 while(1) break; // ok
36 goto foo; // expected-error {{goto not allowed}}
37 });
Steve Naroff61f40a22008-09-10 19:17:48 +000038 break;
Mike Stump1eb44332009-09-09 15:08:12 +000039 }
Steve Naroff61f40a22008-09-10 19:17:48 +000040
Mike Stump1eb44332009-09-09 15:08:12 +000041 foo:
42 takeblock(^{ x = 4; }); // expected-error {{variable is not assignable (missing __block type specifier)}}
Chris Lattner3f84ad22009-04-22 05:27:59 +000043 __block y = 7; // expected-warning {{type specifier missing, defaults to 'int'}}
Mike Stump0e88b162009-08-27 00:29:21 +000044 takeblock(^{ y = 8; });
Steve Naroff61f40a22008-09-10 19:17:48 +000045}
46
47
48void (^test3())(void) {
Mike Stump397195b2009-04-17 00:09:41 +000049 return ^{};
Steve Naroff61f40a22008-09-10 19:17:48 +000050}
51
52void test4() {
53 void (^noop)(void) = ^{};
54 void (*noop2)() = 0;
55}
56
Steve Naroff4f6a7d72008-09-26 14:41:28 +000057void myfunc(int (^block)(int)) {}
58
Eli Friedman5fdeae12009-03-22 23:00:19 +000059void myfunc3(const int *x);
Steve Naroff4f6a7d72008-09-26 14:41:28 +000060
61void test5() {
Mike Stump1eb44332009-09-09 15:08:12 +000062 int a;
Steve Naroff4f6a7d72008-09-26 14:41:28 +000063
Mike Stump1eb44332009-09-09 15:08:12 +000064 myfunc(^(int abcd) {
65 myfunc3(&a);
66 return 1;
Steve Naroff4f6a7d72008-09-26 14:41:28 +000067 });
68}
69
Steve Naroff61f40a22008-09-10 19:17:48 +000070void *X;
71
72void test_arguments() {
Steve Naroff61f40a22008-09-10 19:17:48 +000073 int y;
Steve Naroff61f40a22008-09-10 19:17:48 +000074 int (^c)(char);
75 (1 ? c : 0)('x');
76 (1 ? 0 : c)('x');
77
78 (1 ? c : c)('x');
79}
80
Steve Naroff8af6a452008-10-02 17:12:56 +000081static int global_x = 10;
82void (^global_block)(void) = ^{ printf("global x is %d\n", global_x); };
83
Steve Naroff3aaa4822009-04-16 19:02:57 +000084typedef void (^void_block_t)(void);
85
86static const void_block_t myBlock = ^{ };
87
88static const void_block_t myBlock2 = ^ void(void) { };