blob: c303b8417d94228f96b8affc5ae90cdd97e9d8d8 [file] [log] [blame]
Daniel Dunbar8fbe78f2009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only %s -verify -fblocks
Steve Naroff2752a172008-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 Stumpa5f00ef2009-08-27 00:29:21 +000011void takeblock(T);
Steve Naroff2752a172008-09-10 19:17:48 +000012int takeintint(int (^C)(int)) { return C(4); }
13
14T somefunction() {
Mike Stump11289f42009-09-09 15:08:12 +000015 if (^{ })
16 nothing();
Steve Naroff2752a172008-09-10 19:17:48 +000017
Mike Stump11289f42009-09-09 15:08:12 +000018 noop = ^{};
Steve Naroff2752a172008-09-10 19:17:48 +000019
Mike Stump11289f42009-09-09 15:08:12 +000020 noop = ^{printf("\nClosure\n"); };
Steve Naroff2752a172008-09-10 19:17:48 +000021
Mike Stump11289f42009-09-09 15:08:12 +000022 I(^{ });
Steve Naroff2752a172008-09-10 19:17:48 +000023
Mike Stump11289f42009-09-09 15:08:12 +000024 return ^{printf("\nClosure\n"); };
Steve Naroff2752a172008-09-10 19:17:48 +000025}
26void test2() {
Mike Stump11289f42009-09-09 15:08:12 +000027 int x = 4;
Steve Naroff2752a172008-09-10 19:17:48 +000028
Mike Stump11289f42009-09-09 15:08:12 +000029 takeblock(^{ printf("%d\n", x); });
Steve Naroff2752a172008-09-10 19:17:48 +000030
31 while (1) {
Mike Stump11289f42009-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
Mike Stump314825b2010-01-19 23:08:01 +000036 goto foo; // expected-error {{use of undeclared label 'foo'}}
37 a: goto a; // ok
Mike Stump11289f42009-09-09 15:08:12 +000038 });
Steve Naroff2752a172008-09-10 19:17:48 +000039 break;
Mike Stump11289f42009-09-09 15:08:12 +000040 }
Steve Naroff2752a172008-09-10 19:17:48 +000041
Mike Stump11289f42009-09-09 15:08:12 +000042 foo:
43 takeblock(^{ x = 4; }); // expected-error {{variable is not assignable (missing __block type specifier)}}
Chris Lattnerdc004372009-04-22 05:27:59 +000044 __block y = 7; // expected-warning {{type specifier missing, defaults to 'int'}}
Mike Stumpa5f00ef2009-08-27 00:29:21 +000045 takeblock(^{ y = 8; });
Steve Naroff2752a172008-09-10 19:17:48 +000046}
47
48
49void (^test3())(void) {
Mike Stump5c3285b2009-04-17 00:09:41 +000050 return ^{};
Steve Naroff2752a172008-09-10 19:17:48 +000051}
52
53void test4() {
54 void (^noop)(void) = ^{};
55 void (*noop2)() = 0;
56}
57
Steve Naroffba756cb2008-09-26 14:41:28 +000058void myfunc(int (^block)(int)) {}
59
Eli Friedman7fa3faa2009-03-22 23:00:19 +000060void myfunc3(const int *x);
Steve Naroffba756cb2008-09-26 14:41:28 +000061
62void test5() {
Mike Stump11289f42009-09-09 15:08:12 +000063 int a;
Steve Naroffba756cb2008-09-26 14:41:28 +000064
Mike Stump11289f42009-09-09 15:08:12 +000065 myfunc(^(int abcd) {
66 myfunc3(&a);
67 return 1;
Steve Naroffba756cb2008-09-26 14:41:28 +000068 });
69}
70
Steve Naroff2752a172008-09-10 19:17:48 +000071void *X;
72
73void test_arguments() {
Steve Naroff2752a172008-09-10 19:17:48 +000074 int y;
Steve Naroff2752a172008-09-10 19:17:48 +000075 int (^c)(char);
76 (1 ? c : 0)('x');
77 (1 ? 0 : c)('x');
78
79 (1 ? c : c)('x');
80}
81
Steve Naroffd40a3962008-10-02 17:12:56 +000082static int global_x = 10;
83void (^global_block)(void) = ^{ printf("global x is %d\n", global_x); };
84
Steve Naroffa0c32702009-04-16 19:02:57 +000085typedef void (^void_block_t)(void);
86
87static const void_block_t myBlock = ^{ };
88
89static const void_block_t myBlock2 = ^ void(void) { };