1 /* Test for passing arguments to ObjC methods in the context of template
3 /* Contributed by Ziemowit Laski <zlaski@apple.com>. */
6 /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
7 #include "../objc-obj-c++-shared/TestsuiteObject.m"
10 #define CHECK_IF(expr) if(!(expr)) abort()
12 @interface ObjCClass : TestsuiteObject
18 -(id) initWithInformation: (int) whatInfo;
19 -(id) initWithInformation: (int) whatInfo andInfo: (int) info2;
23 ObjCClass *mObj1 = [[ObjCClass alloc] init];
24 ObjCClass *mObj2 = [[ObjCClass alloc] initWithInformation: info];
25 ObjCClass *mObj3 = [[ObjCClass alloc] initWithInformation: info andInfo: 39];
27 CHECK_IF(mObj1->info == 666);
28 CHECK_IF(mObj2->info == info);
29 CHECK_IF(mObj3->info == info + 39);
32 template <class WrappedObjCClass>
33 class ObjCObjectWrapper
36 ObjCObjectWrapper(int info);
37 WrappedObjCClass *mObj1, *mObj2, *mObj3;
40 template <class WrappedObjCClass>
41 ObjCObjectWrapper<WrappedObjCClass>::ObjCObjectWrapper(int info)
43 mObj1 = [[WrappedObjCClass alloc] init];
44 mObj2 = [[WrappedObjCClass alloc] initWithInformation: info];
45 mObj3 = [[WrappedObjCClass alloc] initWithInformation: info andInfo: 67];
48 @implementation ObjCClass
50 return [self initWithInformation:666];
52 -(id) initWithInformation: (int) whatInfo {
57 -(id) initWithInformation: (int) whatInfo andInfo: (int) info2 {
59 info = whatInfo + info2;
64 ObjCObjectWrapper<ObjCClass> staticInstance(42);
67 ObjCObjectWrapper<ObjCClass> stackInstance(47);
71 CHECK_IF(staticInstance.mObj1->info == 666);
72 CHECK_IF(staticInstance.mObj2->info == 42);
73 CHECK_IF(staticInstance.mObj3->info == 42 + 67);
75 CHECK_IF(stackInstance.mObj1->info == 666);
76 CHECK_IF(stackInstance.mObj2->info == 47);
77 CHECK_IF(stackInstance.mObj3->info == 47 + 67);