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