| 1 |
// RUN: %clang_cc1 -x objective-c++ -fblocks -triple x86_64-apple-darwin -fobjc-runtime=macosx-fragile-10.5 %s -verify -std=c++11 -emit-llvm -o %t |
| 2 |
|
| 3 |
@interface A |
| 4 |
@end |
| 5 |
|
| 6 |
@interface B : A |
| 7 |
@end |
| 8 |
|
| 9 |
void f(int (^bl)(B* b)); |
| 10 |
void takeBlock(void (^block)()); |
| 11 |
void useValues(...); |
| 12 |
|
| 13 |
// Test1 |
| 14 |
void g() { |
| 15 |
f(^(A* a) { return 0; }); |
| 16 |
} |
| 17 |
|
| 18 |
// Test2 |
| 19 |
void g1() { |
| 20 |
int (^bl)(B* b) = ^(A* a) { return 0; }; |
| 21 |
} |
| 22 |
|
| 23 |
// Test3 |
| 24 |
@protocol NSObject; |
| 25 |
|
| 26 |
void bar(id(^)(void)); |
| 27 |
|
| 28 |
void foo(id <NSObject>(^objectCreationBlock)(void)) { |
| 29 |
return bar(objectCreationBlock); |
| 30 |
} |
| 31 |
|
| 32 |
// Test4 |
| 33 |
struct S { |
| 34 |
S *(^a)() = ^{ |
| 35 |
return this; |
| 36 |
}; |
| 37 |
}; |
| 38 |
S s; |
| 39 |
|
| 40 |
// Test5 |
| 41 |
struct X { |
| 42 |
void f() { |
| 43 |
^ { |
| 44 |
struct Nested { Nested *ptr = this; }; |
| 45 |
} (); |
| 46 |
}; |
| 47 |
}; |
| 48 |
|
| 49 |
// Regression test for PR13314 |
| 50 |
class FooClass { }; |
| 51 |
void fun() { |
| 52 |
FooClass foovar; |
| 53 |
^() { // expected-warning {{expression result unused}} |
| 54 |
return foovar; |
| 55 |
}; |
| 56 |
} |
| 57 |
void gun() { |
| 58 |
FooClass foovar; |
| 59 |
[=]() { // expected-warning {{expression result unused}} |
| 60 |
return foovar; |
| 61 |
}; |
| 62 |
} |
| 63 |
|
| 64 |
// PR24780 |
| 65 |
class CaptureThisAndAnotherPointer { |
| 66 |
void test(void *ptr) { |
| 67 |
takeBlock(^{ useValues(ptr, this); }); |
| 68 |
} |
| 69 |
}; |
| 70 |
|
| 71 |
// Check that we don't crash when using BLOCK_LAYOUT_STRONG. |
| 72 |
#pragma clang assume_nonnull begin |
| 73 |
@interface NSUUID @end |
| 74 |
#pragma clang assume_nonnull end |
| 75 |
|
| 76 |
struct Wrapper1 { NSUUID *Ref; }; |
| 77 |
struct Wrapper2 { Wrapper1 W1; }; |
| 78 |
|
| 79 |
@implementation B |
| 80 |
- (void) captureStrongRef { |
| 81 |
__block Wrapper2 W2; |
| 82 |
} |
| 83 |
@end |