diff options
author | Carlo Zancanaro <carlo@pc-4w14-0.cs.usyd.edu.au> | 2012-10-15 17:10:06 +1100 |
---|---|---|
committer | Carlo Zancanaro <carlo@pc-4w14-0.cs.usyd.edu.au> | 2012-10-15 17:10:06 +1100 |
commit | be1de4be954c80875ad4108e0a33e8e131b2f2c0 (patch) | |
tree | 1fbbecf276bf7c7bdcbb4dd446099d6d90eaa516 /clang/test/Sema/block-literal.c | |
parent | c4626a62754862d20b41e8a46a3574264ea80e6d (diff) | |
parent | f1bd2e48c5324d3f7cda4090c87f8a5b6f463ce2 (diff) |
Merge branch 'master' of ssh://bitbucket.org/czan/honours
Diffstat (limited to 'clang/test/Sema/block-literal.c')
-rw-r--r-- | clang/test/Sema/block-literal.c | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/clang/test/Sema/block-literal.c b/clang/test/Sema/block-literal.c new file mode 100644 index 0000000..c303b84 --- /dev/null +++ b/clang/test/Sema/block-literal.c @@ -0,0 +1,89 @@ +// RUN: %clang_cc1 -fsyntax-only %s -verify -fblocks + +void I( void (^)(void)); +void (^noop)(void); + +void nothing(); +int printf(const char*, ...); + +typedef void (^T) (void); + +void takeblock(T); +int takeintint(int (^C)(int)) { return C(4); } + +T somefunction() { + if (^{ }) + nothing(); + + noop = ^{}; + + noop = ^{printf("\nClosure\n"); }; + + I(^{ }); + + return ^{printf("\nClosure\n"); }; +} +void test2() { + int x = 4; + + takeblock(^{ printf("%d\n", x); }); + + while (1) { + takeblock(^{ + break; // expected-error {{'break' statement not in loop or switch statement}} + continue; // expected-error {{'continue' statement not in loop statement}} + while(1) break; // ok + goto foo; // expected-error {{use of undeclared label 'foo'}} + a: goto a; // ok + }); + break; + } + + foo: + takeblock(^{ x = 4; }); // expected-error {{variable is not assignable (missing __block type specifier)}} + __block y = 7; // expected-warning {{type specifier missing, defaults to 'int'}} + takeblock(^{ y = 8; }); +} + + +void (^test3())(void) { + return ^{}; +} + +void test4() { + void (^noop)(void) = ^{}; + void (*noop2)() = 0; +} + +void myfunc(int (^block)(int)) {} + +void myfunc3(const int *x); + +void test5() { + int a; + + myfunc(^(int abcd) { + myfunc3(&a); + return 1; + }); +} + +void *X; + +void test_arguments() { + int y; + int (^c)(char); + (1 ? c : 0)('x'); + (1 ? 0 : c)('x'); + + (1 ? c : c)('x'); +} + +static int global_x = 10; +void (^global_block)(void) = ^{ printf("global x is %d\n", global_x); }; + +typedef void (^void_block_t)(void); + +static const void_block_t myBlock = ^{ }; + +static const void_block_t myBlock2 = ^ void(void) { }; |