]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/SemaTemplate/instantiate-local-class.cpp
Vendor import of clang release_34 branch r197841 (effectively, 3.4 RC3):
[FreeBSD/FreeBSD.git] / test / SemaTemplate / instantiate-local-class.cpp
1 // RUN: %clang_cc1 -verify -std=c++11 %s
2 // expected-no-diagnostics
3 template<typename T>
4 void f0() {
5   struct X;
6   typedef struct Y {
7     T (X::* f1())(int) { return 0; }
8   } Y2;
9
10   Y2 y = Y();
11 }
12
13 template void f0<int>();
14
15 // PR5764
16 namespace PR5764 {
17   struct X {
18     template <typename T>
19     void Bar() {
20       typedef T ValueType;
21       struct Y {
22         Y() { V = ValueType(); }
23
24         ValueType V;
25       };
26
27       Y y;
28     }
29   };
30
31   void test(X x) {
32     x.Bar<int>();
33   }
34 }
35
36 // Instantiation of local classes with virtual functions.
37 namespace local_class_with_virtual_functions {
38   template <typename T> struct X { };
39   template <typename T> struct Y { };
40
41   template <typename T>
42   void f() {
43     struct Z : public X<Y<T>*> {
44       virtual void g(Y<T>* y) { }
45       void g2(int x) {(void)x;}
46     };
47     Z z;
48     (void)z;
49   }
50
51   struct S { };
52   void test() { f<S>(); }
53 }
54
55 namespace PR8801 {
56   template<typename T>
57   void foo() {
58     class X;
59     typedef int (X::*pmf_type)();
60     class X : public T { };
61     
62     pmf_type pmf = &T::foo;
63   }
64
65   struct Y { int foo(); };
66
67   template void foo<Y>();
68 }
69
70 namespace TemplatePacksAndLambdas {
71   template <typename ...T> int g(T...);
72   struct S {
73     template <typename ...T> static void f(int f = g([]{ static T t; return ++t; }()...)) {}
74   };
75   void h() { S::f<int, int, int>(); }
76 }
77
78 namespace PR9685 {
79   template <class Thing> void forEach(Thing t) { t.func(); }
80
81   template <typename T> void doIt() {
82     struct Functor {
83       void func() { (void)i; }
84       int i;
85     };
86
87     forEach(Functor());
88   }
89
90   void call() {
91     doIt<int>();
92   }
93 }
94
95 namespace PR12702 {
96   struct S {
97     template <typename F> bool apply(F f) { return f(); }
98   };
99
100   template <typename> struct T {
101     void foo() {
102       struct F {
103         int x;
104
105         bool operator()() { return x == 0; }
106       };
107
108       S().apply(F());
109     }
110   };
111
112   void call() { T<int>().foo(); }
113 }
114
115 namespace PR17139 {
116   template <class T> void foo(const T &t) { t.foo(); }
117
118   template <class F> void bar(F *f) {
119     struct B {
120       F *fn;
121       void foo() const { fn(); }
122     } b = { f };
123     foo(b);
124   }
125
126   void go() {}
127
128   void test() { bar(go); }
129 }
130
131 namespace PR17740 {
132 class C {
133 public:
134   template <typename T> static void foo(T function);
135   template <typename T> static void bar(T function);
136   template <typename T> static void func(T function);
137 };
138
139 template <typename T> void C::foo(T function) { function(); }
140
141 template <typename T> void C::bar(T function) {
142   foo([&function]() { function(); });
143 }
144
145 template <typename T> void C::func(T function) {
146   struct Struct {
147     T mFunction;
148
149     Struct(T function) : mFunction(function) {};
150
151     void operator()() {
152       mFunction();
153     };
154   };
155
156   bar(Struct(function));
157 }
158
159 void call() {
160   C::func([]() {});
161 }
162 }
163
164 namespace PR14373 {
165   struct function {
166     template <typename _Functor> function(_Functor __f) { __f(); }
167   };
168   template <typename Func> function exec_func(Func f) {
169     struct functor {
170       functor(Func f) : func(f) {}
171       void operator()() const { func(); }
172       Func func;
173     };
174     return functor(f);
175   }
176   struct Type {
177     void operator()() const {}
178   };
179   int call() {
180     exec_func(Type());
181     return 0;
182   }
183 }