* gcc.dg/vect/vect-shift-1.c: Include tree-vect.h header. Check
[official-gcc.git] / gcc / testsuite / obj-c++.dg / method-19.mm
blob55890f5b404dea0a6e20605e2d9388432aa53277
1 /* Test if instance methods of root classes are used as class methods, if no
2    "real" methods are found.  For receivers of type 'id' and 'Class', all
3    root classes must be considered.  */
4 /* Author: Ziemowit Laski <zlaski@apple.com>.  */
5 /* { dg-do run } */
7 #include <objc/objc.h>
9 #ifdef __NEXT_RUNTIME__
10 #include <objc/objc-runtime.h>
11 #define OBJC_GETCLASS objc_getClass
12 #else
13 #include <objc/objc-api.h>
14 #define OBJC_GETCLASS objc_get_class
15 #endif
17 extern "C" {
18   extern void abort(void);
19   extern int strcmp(const char *, const char *);
21 #define CHECK_IF(expr) if(!(expr)) abort()
23 @protocol Proto
24 - (const char *) method4;
25 @end
27 @interface Root
28 { Class isa; }
29 + (const char *) method2;
30 @end
32 @interface Derived: Root
33 - (const char *) method1;
34 - (const char *) method2;
35 - (const char *) method3;
36 @end
38 @interface Root (Categ)
39 - (const char *) method3;
40 @end
42 @implementation Root (Categ)
43 - (const char *) method3 { return "Root(Categ)::-method3"; }
44 - (const char *) method4 { return "Root(Categ)::-method4"; }
45 @end
47 @implementation Derived
48 - (const char *) method1 { return "Derived::-method1"; }
49 - (const char *) method2 { return "Derived::-method2"; }
50 - (const char *) method3 { return "Derived::-method3"; }
51 @end
53 @implementation Root
54 #ifdef __NEXT_RUNTIME__
55 + initialize { return self; }
56 #endif
57 - (const char *) method1 { return "Root::-method1"; }
58 + (const char *) method2 { return "Root::+method2"; }
59 @end
61 int main(void)
63   Class obj = OBJC_GETCLASS("Derived");
65   /* None of the following should elicit compiler-time warnings.  */
67   CHECK_IF(!strcmp([Root method1], "Root::-method1"));
68   CHECK_IF(!strcmp([Root method2], "Root::+method2"));
69   CHECK_IF(!strcmp([Root method3], "Root(Categ)::-method3"));
70   CHECK_IF(!strcmp([Root method4], "Root(Categ)::-method4"));
71   CHECK_IF(!strcmp([Derived method1], "Root::-method1"));
72   CHECK_IF(!strcmp([Derived method2], "Root::+method2"));
73   CHECK_IF(!strcmp([Derived method3], "Root(Categ)::-method3"));
74   CHECK_IF(!strcmp([Derived method4], "Root(Categ)::-method4"));
75   CHECK_IF(!strcmp([obj method1], "Root::-method1"));
76   CHECK_IF(!strcmp([obj method2], "Root::+method2"));
77   CHECK_IF(!strcmp([obj method3], "Root(Categ)::-method3"));
78   CHECK_IF(!strcmp([obj method4], "Root(Categ)::-method4"));
80   return 0;