From 1bc5aee63eb72b341f506ad058502cd0361f0d10 Mon Sep 17 00:00:00 2001 From: Ben Cheng Date: Tue, 25 Mar 2014 22:37:19 -0700 Subject: Initial checkin of GCC 4.9.0 from trunk (r208799). Change-Id: I48a3c08bb98542aa215912a75f03c0890e497dba --- gcc-4.9/gcc/testsuite/obj-c++.dg/template-3.mm | 81 ++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 gcc-4.9/gcc/testsuite/obj-c++.dg/template-3.mm (limited to 'gcc-4.9/gcc/testsuite/obj-c++.dg/template-3.mm') diff --git a/gcc-4.9/gcc/testsuite/obj-c++.dg/template-3.mm b/gcc-4.9/gcc/testsuite/obj-c++.dg/template-3.mm new file mode 100644 index 000000000..c564733cf --- /dev/null +++ b/gcc-4.9/gcc/testsuite/obj-c++.dg/template-3.mm @@ -0,0 +1,81 @@ +/* Test for passing arguments to ObjC methods in the context of template + expansion. */ +/* Contributed by Ziemowit Laski . */ + +/* { dg-do run } */ +/* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */ +#include "../objc-obj-c++-shared/TestsuiteObject.m" +#include + +#define CHECK_IF(expr) if(!(expr)) abort() + +@interface ObjCClass : TestsuiteObject +{ +@public + int info; +} +-(id) init; +-(id) initWithInformation: (int) whatInfo; +-(id) initWithInformation: (int) whatInfo andInfo: (int) info2; +@end + +void foo(int info) { + ObjCClass *mObj1 = [[ObjCClass alloc] init]; + ObjCClass *mObj2 = [[ObjCClass alloc] initWithInformation: info]; + ObjCClass *mObj3 = [[ObjCClass alloc] initWithInformation: info andInfo: 39]; + + CHECK_IF(mObj1->info == 666); + CHECK_IF(mObj2->info == info); + CHECK_IF(mObj3->info == info + 39); +} + +template +class ObjCObjectWrapper +{ + public: + ObjCObjectWrapper(int info); + WrappedObjCClass *mObj1, *mObj2, *mObj3; +}; + +template +ObjCObjectWrapper::ObjCObjectWrapper(int info) +{ + mObj1 = [[WrappedObjCClass alloc] init]; + mObj2 = [[WrappedObjCClass alloc] initWithInformation: info]; + mObj3 = [[WrappedObjCClass alloc] initWithInformation: info andInfo: 67]; +} + +@implementation ObjCClass +-(id) init { + return [self initWithInformation:666]; +} +-(id) initWithInformation: (int) whatInfo { + [super init]; + info = whatInfo; + return self; +} +-(id) initWithInformation: (int) whatInfo andInfo: (int) info2 { + [super init]; + info = whatInfo + info2; + return self; +} +@end + +ObjCObjectWrapper staticInstance(42); + +int main(void) { + ObjCObjectWrapper stackInstance(47); + + foo(89); + + CHECK_IF(staticInstance.mObj1->info == 666); + CHECK_IF(staticInstance.mObj2->info == 42); + CHECK_IF(staticInstance.mObj3->info == 42 + 67); + + CHECK_IF(stackInstance.mObj1->info == 666); + CHECK_IF(stackInstance.mObj2->info == 47); + CHECK_IF(stackInstance.mObj3->info == 47 + 67); + + return 0; +} + -- cgit v1.2.3