OSDN Git Service

4b0a3df6c639c7b299211ccced49177228ac561c
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / obj-c++.dg / template-1.mm
1 /* Test for using ObjC classes as C++ template parameters.  */
2 /* Author:  Ziemowit Laski <zlaski@apple.com>.  */
3
4 /* { dg-do run } */
5
6 #include <objc/Object.h>
7 #include <stdlib.h>
8
9 #define CHECK_IF(expr) if(!(expr)) abort()
10
11 @interface Base: Object
12 - (int) meth;
13 @end
14
15 @interface Derived: Base   
16 - (int) meth;                
17 @end
18
19 static int count = 0;
20
21 template <class T> struct Templ
22 {
23   T *m;
24   int i;
25   Templ(): i(55), m([[T alloc] init]) { count++; }
26   ~Templ() { [m free]; count--; }
27 };
28
29 @implementation Base
30 - (int) meth { return 333; }
31 @end
32
33 @implementation Derived
34 - (int) meth { return 666; }
35 @end
36         
37 int main (void) {
38   CHECK_IF(count == 0);
39   {
40     Templ<Derived> derived;
41     CHECK_IF(derived.i == 55 && count == 1);
42     Templ<Base> base;
43     CHECK_IF(base.i == 55 && count == 2);
44     CHECK_IF([base.m meth] == 333);
45     CHECK_IF([derived.m meth] == 666);
46   }
47   CHECK_IF(count == 0);
48   return 0;
49 }