Debian Codegraph @

clang/test/Rewriter/rewrite-block-literal.mm

raw
1 // RUN: %clang_cc1 -E %s -o %t.mm
2 // RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %t.mm -o - | FileCheck %s
3 // RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-runtime=macosx-fragile-10.5 %s -o %t-rw.cpp
4 // RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"Class=void*" -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp
5 // RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-modern-rw.cpp
6 // RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"Class=void*" -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-modern-rw.cpp
7
8 typedef unsigned long size_t;
9
10 void I( void (^)(void));
11 void (^noop)(void);
12
13 void nothing();
14 int printf(const char*, ...);
15
16 typedef void (^T) (void);
17
18 void takeblock(T);
19 int takeintint(int (^C)(int)) { return C(4); }
20
21 T somefunction() {
22 if (^{ })
23 nothing();
24
25 noop = ^{};
26
27 noop = ^{printf("\nClosure\n"); };
28
29 I(^{ });
30
31 return ^{printf("\nClosure\n"); };
32 }
33 void test2() {
34 int x = 4;
35
36 takeblock(^{ printf("%d\n", x); });
37
38 while (1) {
39 takeblock(^{
40 while(1) break; // ok
41 });
42 break;
43 }
44 }
45
46 void test4() {
47 void (^noop)(void) = ^{};
48 void (*noop2)() = 0;
49 }
50
51 void myfunc(int (^block)(int)) {}
52
53 void myfunc3(const int *x);
54
55 void test5() {
56 int a;
57
58 myfunc(^(int abcd) {
59 myfunc3(&a);
60 return 1;
61 });
62 }
63
64 void *X;
65
66 static int global_x = 10;
67 void (^global_block)(void) = ^{ printf("global x is %d\n", global_x); };
68
69 // CHECK: static __global_block_block_impl_0 __global_global_block_block_impl_0((void *)__global_block_block_func_0, &__global_block_block_desc_0_DATA);
70 // CHECK: void (*global_block)(void) = ((void (*)())&__global_global_block_block_impl_0);
71
72 typedef void (^void_block_t)(void);
73
74 static const void_block_t myBlock = ^{ };
75
76 static const void_block_t myBlock2 = ^ void(void) { };