OSDN Git Service

In gcc/objc/:
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / obj-c++.dg / template-8.mm
1 /* Test that all pending instantiations have taken place before meta-data
2    generation. */       
3 /* Author: Fariborz Jahanian <fjahanian@apple.com> */
4 /* Adapted by Nicola Pero <nicola.pero@meta-innovation.com> */
5 /* { dg-do run } */
6 /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
7
8 #include <objc/objc.h>
9 #include <objc/runtime.h>
10
11 @interface MyRootClass
12 { Class isa; }
13 + (id) initialize;
14 + alloc;
15 - init;
16 - doSomething;
17 @end
18
19 @implementation MyRootClass
20 + (id) initialize { return self; }
21 + alloc { return class_createInstance (self, 0); }
22 - init  { return self; }
23 - doSomething { return self; }
24 @end
25
26 class Base
27 {
28 public:
29         Base() { }
30         virtual ~Base() { }
31         
32         void destroy() { delete this; }
33 };
34
35 template<class T>
36 class Subclass : public T
37 {
38 public:
39         Subclass() { }
40         
41         virtual ~Subclass()
42         {
43                 [[[MyRootClass alloc] init] doSomething];
44         }
45 };
46
47 int main(int argc, const char * argv[])
48 {
49     Subclass<Base>* theSubclass = new Subclass<Base>();
50     theSubclass->destroy();
51     return 0;
52 }