xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenObjCXX/blocks.mm (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc// 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*f4a2713aSLionel Sambuc// rdar://8979379
3*f4a2713aSLionel Sambuc
4*f4a2713aSLionel Sambuc@interface A
5*f4a2713aSLionel Sambuc@end
6*f4a2713aSLionel Sambuc
7*f4a2713aSLionel Sambuc@interface B : A
8*f4a2713aSLionel Sambuc@end
9*f4a2713aSLionel Sambuc
10*f4a2713aSLionel Sambucvoid f(int (^bl)(B* b));
11*f4a2713aSLionel Sambuc
12*f4a2713aSLionel Sambuc// Test1
13*f4a2713aSLionel Sambucvoid g() {
14*f4a2713aSLionel Sambuc  f(^(A* a) { return 0; });
15*f4a2713aSLionel Sambuc}
16*f4a2713aSLionel Sambuc
17*f4a2713aSLionel Sambuc// Test2
18*f4a2713aSLionel Sambucvoid g1() {
19*f4a2713aSLionel Sambuc  int (^bl)(B* b) = ^(A* a) { return 0; };
20*f4a2713aSLionel Sambuc}
21*f4a2713aSLionel Sambuc
22*f4a2713aSLionel Sambuc// Test3
23*f4a2713aSLionel Sambuc@protocol NSObject;
24*f4a2713aSLionel Sambuc
25*f4a2713aSLionel Sambucvoid bar(id(^)(void));
26*f4a2713aSLionel Sambuc
27*f4a2713aSLionel Sambucvoid foo(id <NSObject>(^objectCreationBlock)(void)) {
28*f4a2713aSLionel Sambuc    return bar(objectCreationBlock);
29*f4a2713aSLionel Sambuc}
30*f4a2713aSLionel Sambuc
31*f4a2713aSLionel Sambuc// Test4
32*f4a2713aSLionel Sambucstruct S {
33*f4a2713aSLionel Sambuc  S *(^a)() = ^{
34*f4a2713aSLionel Sambuc    return this;
35*f4a2713aSLionel Sambuc  };
36*f4a2713aSLionel Sambuc};
37*f4a2713aSLionel SambucS s;
38*f4a2713aSLionel Sambuc
39*f4a2713aSLionel Sambuc// Test5
40*f4a2713aSLionel Sambucstruct X {
41*f4a2713aSLionel Sambuc  void f() {
42*f4a2713aSLionel Sambuc    ^ {
43*f4a2713aSLionel Sambuc      struct Nested { Nested *ptr = this; };
44*f4a2713aSLionel Sambuc    } ();
45*f4a2713aSLionel Sambuc  };
46*f4a2713aSLionel Sambuc};
47*f4a2713aSLionel Sambuc
48*f4a2713aSLionel Sambuc// Regression test for PR13314
49*f4a2713aSLionel Sambucclass FooClass { };
50*f4a2713aSLionel Sambucvoid fun() {
51*f4a2713aSLionel Sambuc  FooClass foovar;
52*f4a2713aSLionel Sambuc  ^() {  // expected-warning {{expression result unused}}
53*f4a2713aSLionel Sambuc    return foovar;
54*f4a2713aSLionel Sambuc  };
55*f4a2713aSLionel Sambuc}
56*f4a2713aSLionel Sambucvoid gun() {
57*f4a2713aSLionel Sambuc  FooClass foovar;
58*f4a2713aSLionel Sambuc  [=]() {  // expected-warning {{expression result unused}}
59*f4a2713aSLionel Sambuc    return foovar;
60*f4a2713aSLionel Sambuc  };
61*f4a2713aSLionel Sambuc}
62