xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenObjCXX/block-in-template-inst.mm (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc// RUN: %clang_cc1 -emit-llvm-only -std=c++11 -fblocks -o - -triple x86_64-apple-darwin10 -fobjc-runtime=macosx-fragile-10.5 %s
2*f4a2713aSLionel Sambuc// rdar://9362021
3*f4a2713aSLionel Sambuc
4*f4a2713aSLionel Sambuc@class DYFuture;
5*f4a2713aSLionel Sambuc@interface NSCache
6*f4a2713aSLionel Sambuc- (void)setObject:(id)obj forKey:(id)key;
7*f4a2713aSLionel Sambuc@end
8*f4a2713aSLionel Sambuc
9*f4a2713aSLionel Sambuctemplate <typename T>
10*f4a2713aSLionel Sambucclass ResourceManager
11*f4a2713aSLionel Sambuc{
12*f4a2713aSLionel Sambucpublic:
13*f4a2713aSLionel Sambuc ~ResourceManager();
14*f4a2713aSLionel Sambuc DYFuture* XXX();
15*f4a2713aSLionel Sambuc NSCache* _spDeviceCache;
16*f4a2713aSLionel Sambuc};
17*f4a2713aSLionel Sambuc
18*f4a2713aSLionel Sambuctemplate <typename T>
19*f4a2713aSLionel SambucDYFuture* ResourceManager<T>::XXX()
20*f4a2713aSLionel Sambuc{
21*f4a2713aSLionel Sambuc ^ {
22*f4a2713aSLionel Sambuc   [_spDeviceCache setObject:0 forKey:0];
23*f4a2713aSLionel Sambuc  }();
24*f4a2713aSLionel Sambuc
25*f4a2713aSLionel Sambuc return 0;
26*f4a2713aSLionel Sambuc}
27*f4a2713aSLionel Sambuc
28*f4a2713aSLionel Sambucstruct AnalyzerBaseObjectTypes { };
29*f4a2713aSLionel Sambuc
30*f4a2713aSLionel Sambucvoid FUNC()
31*f4a2713aSLionel Sambuc{
32*f4a2713aSLionel Sambuc    ResourceManager<AnalyzerBaseObjectTypes> *rm;
33*f4a2713aSLionel Sambuc    ^(void) { rm->XXX(); }();
34*f4a2713aSLionel Sambuc}
35*f4a2713aSLionel Sambuc
36*f4a2713aSLionel Sambucnamespace PR9982 {
37*f4a2713aSLionel Sambuc  template<typename T> struct Curry;
38*f4a2713aSLionel Sambuc
39*f4a2713aSLionel Sambuc  template<typename R, typename Arg0, typename Arg1, typename Arg2>
40*f4a2713aSLionel Sambuc    struct Curry<R (^)(Arg0, Arg1, Arg2)>
41*f4a2713aSLionel Sambuc    {
42*f4a2713aSLionel Sambuc      typedef R (^FType)(Arg0, Arg1, Arg2);
43*f4a2713aSLionel Sambuc
44*f4a2713aSLionel Sambuc    Curry(FType _f) : f(_f) {}
45*f4a2713aSLionel Sambuc      ~Curry() {;}
46*f4a2713aSLionel Sambuc
47*f4a2713aSLionel Sambuc      R (^(^operator()(Arg0 a))(Arg1))(Arg2)
48*f4a2713aSLionel Sambuc      {
49*f4a2713aSLionel Sambuc        auto block = ^(Arg1 b) {
50*f4a2713aSLionel Sambuc          auto inner_block = ^(Arg2 c) {
51*f4a2713aSLionel Sambuc            return f(a, b, c);
52*f4a2713aSLionel Sambuc          };
53*f4a2713aSLionel Sambuc          return inner_block;
54*f4a2713aSLionel Sambuc        };
55*f4a2713aSLionel Sambuc        return block;
56*f4a2713aSLionel Sambuc      }
57*f4a2713aSLionel Sambuc
58*f4a2713aSLionel Sambuc    private:
59*f4a2713aSLionel Sambuc      FType f;
60*f4a2713aSLionel Sambuc    };
61*f4a2713aSLionel Sambuc
62*f4a2713aSLionel Sambuc  auto add = ^(int a, int b, int c)
63*f4a2713aSLionel Sambuc    {
64*f4a2713aSLionel Sambuc      return a + b + c;
65*f4a2713aSLionel Sambuc    };
66*f4a2713aSLionel Sambuc
67*f4a2713aSLionel Sambuc  void curry() {
68*f4a2713aSLionel Sambuc    Curry<__decltype(add)> c = Curry<__decltype(add)>(add);
69*f4a2713aSLionel Sambuc    auto t = c(1)(10)(100);
70*f4a2713aSLionel Sambuc  }
71*f4a2713aSLionel Sambuc}
72