OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gcc-4.2.2/] [gcc/] [testsuite/] [obj-c++.dg/] [template-3.mm] - Diff between revs 149 and 154

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 149 Rev 154
/* Test for passing arguments to ObjC methods in the context of template
/* Test for passing arguments to ObjC methods in the context of template
   expansion.  */
   expansion.  */
/* Contributed by Ziemowit Laski  .  */
/* Contributed by Ziemowit Laski  .  */
/* { dg-do run } */
/* { dg-do run } */
#include 
#include 
#include 
#include 
#define CHECK_IF(expr) if(!(expr)) abort()
#define CHECK_IF(expr) if(!(expr)) abort()
@interface ObjCClass : Object
@interface ObjCClass : Object
{
{
@public
@public
  int info;
  int info;
}
}
-(id) init;
-(id) init;
-(id) initWithInformation: (int) whatInfo;
-(id) initWithInformation: (int) whatInfo;
-(id) initWithInformation: (int) whatInfo andInfo: (int) info2;
-(id) initWithInformation: (int) whatInfo andInfo: (int) info2;
@end
@end
void foo(int info) {
void foo(int info) {
   ObjCClass *mObj1 = [[ObjCClass alloc] init];
   ObjCClass *mObj1 = [[ObjCClass alloc] init];
   ObjCClass *mObj2 = [[ObjCClass alloc] initWithInformation: info];
   ObjCClass *mObj2 = [[ObjCClass alloc] initWithInformation: info];
   ObjCClass *mObj3 = [[ObjCClass alloc] initWithInformation: info andInfo: 39];
   ObjCClass *mObj3 = [[ObjCClass alloc] initWithInformation: info andInfo: 39];
   CHECK_IF(mObj1->info == 666);
   CHECK_IF(mObj1->info == 666);
   CHECK_IF(mObj2->info == info);
   CHECK_IF(mObj2->info == info);
   CHECK_IF(mObj3->info == info + 39);
   CHECK_IF(mObj3->info == info + 39);
}
}
template 
template 
class ObjCObjectWrapper
class ObjCObjectWrapper
{
{
    public:
    public:
        ObjCObjectWrapper(int info);
        ObjCObjectWrapper(int info);
        WrappedObjCClass *mObj1, *mObj2, *mObj3;
        WrappedObjCClass *mObj1, *mObj2, *mObj3;
};
};
template 
template 
ObjCObjectWrapper::ObjCObjectWrapper(int info)
ObjCObjectWrapper::ObjCObjectWrapper(int info)
{
{
    mObj1 = [[WrappedObjCClass alloc] init];
    mObj1 = [[WrappedObjCClass alloc] init];
    mObj2 = [[WrappedObjCClass alloc] initWithInformation: info];
    mObj2 = [[WrappedObjCClass alloc] initWithInformation: info];
    mObj3 = [[WrappedObjCClass alloc] initWithInformation: info andInfo: 67];
    mObj3 = [[WrappedObjCClass alloc] initWithInformation: info andInfo: 67];
}
}
@implementation ObjCClass
@implementation ObjCClass
-(id) init {
-(id) init {
  return [self initWithInformation:666];
  return [self initWithInformation:666];
}
}
-(id) initWithInformation: (int) whatInfo {
-(id) initWithInformation: (int) whatInfo {
  [super init];
  [super init];
  info = whatInfo;
  info = whatInfo;
  return self;
  return self;
}
}
-(id) initWithInformation: (int) whatInfo andInfo: (int) info2 {
-(id) initWithInformation: (int) whatInfo andInfo: (int) info2 {
  [super init];
  [super init];
  info = whatInfo + info2;
  info = whatInfo + info2;
  return self;
  return self;
}
}
@end
@end
ObjCObjectWrapper staticInstance(42);
ObjCObjectWrapper staticInstance(42);
int main(void) {
int main(void) {
  ObjCObjectWrapper stackInstance(47);
  ObjCObjectWrapper stackInstance(47);
  foo(89);
  foo(89);
  CHECK_IF(staticInstance.mObj1->info == 666);
  CHECK_IF(staticInstance.mObj1->info == 666);
  CHECK_IF(staticInstance.mObj2->info == 42);
  CHECK_IF(staticInstance.mObj2->info == 42);
  CHECK_IF(staticInstance.mObj3->info == 42 + 67);
  CHECK_IF(staticInstance.mObj3->info == 42 + 67);
  CHECK_IF(stackInstance.mObj1->info == 666);
  CHECK_IF(stackInstance.mObj1->info == 666);
  CHECK_IF(stackInstance.mObj2->info == 47);
  CHECK_IF(stackInstance.mObj2->info == 47);
  CHECK_IF(stackInstance.mObj3->info == 47 + 67);
  CHECK_IF(stackInstance.mObj3->info == 47 + 67);
  return 0;
  return 0;
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.