c++: Add [dcl.init.aggr] examples to testsuite
[official-gcc.git] / gcc / testsuite / objc.dg / method-13.m
blob3e0fde5f5bab62ab35de83f80423ea7d1f7d8bee
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 } */
6 /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
7 /* { dg-additional-options "-Wno-objc-root-class" } */
9 #include <objc/objc.h>
10 #include "../objc-obj-c++-shared/runtime.h"
12 extern void abort(void);
13 extern int strcmp(const char *, const char *);
14 #define CHECK_IF(expr) if(!(expr)) abort()
16 @protocol Proto
17 - (const char *) method4;
18 @end
20 @interface Root
21 { Class isa; }
22 + (const char *) method2;
23 @end
25 @interface Derived: Root
26 - (const char *) method1;
27 - (const char *) method2;
28 - (const char *) method3;
29 @end
31 @interface Root (Categ)
32 - (const char *) method3;
33 @end
35 @implementation Root (Categ)
36 - (const char *) method3 { return "Root(Categ)::-method3"; }
37 - (const char *) method4 { return "Root(Categ)::-method4"; }
38 @end
40 @implementation Derived
41 - (const char *) method1 { return "Derived::-method1"; }
42 - (const char *) method2 { return "Derived::-method2"; }
43 - (const char *) method3 { return "Derived::-method3"; }
44 @end
46 @implementation Root
47 + initialize { return self; }
48 - (const char *) method1 { return "Root::-method1"; }
49 + (const char *) method2 { return "Root::+method2"; }
50 @end
52 int main(void)
54   Class obj = objc_getClass("Derived");
56   /* None of the following should elicit compiler-time warnings.  */
58   CHECK_IF(!strcmp([Root method1], "Root::-method1"));
59   CHECK_IF(!strcmp([Root method2], "Root::+method2"));
60   CHECK_IF(!strcmp([Root method3], "Root(Categ)::-method3"));
61   CHECK_IF(!strcmp([Root method4], "Root(Categ)::-method4"));
62   CHECK_IF(!strcmp([Derived method1], "Root::-method1"));
63   CHECK_IF(!strcmp([Derived method2], "Root::+method2"));
64   CHECK_IF(!strcmp([Derived method3], "Root(Categ)::-method3"));
65   CHECK_IF(!strcmp([Derived method4], "Root(Categ)::-method4"));
66   CHECK_IF(!strcmp([obj method1], "Root::-method1"));
67   CHECK_IF(!strcmp([obj method2], "Root::+method2"));
68   CHECK_IF(!strcmp([obj method3], "Root(Categ)::-method3"));
69   CHECK_IF(!strcmp([obj method4], "Root(Categ)::-method4"));
71   return 0;