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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-stable/] [gcc-4.5.1/] [gcc/] [testsuite/] [obj-c++.dg/] [template-3.mm] - Blame information for rev 826

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 308 jeremybenn
/* Test for passing arguments to ObjC methods in the context of template
2
   expansion.  */
3
/* Contributed by Ziemowit Laski  .  */
4
 
5
/* { dg-do run } */
6
/* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
7
#include "../objc-obj-c++-shared/Object1.h"
8
#include 
9
 
10
#define CHECK_IF(expr) if(!(expr)) abort()
11
 
12
@interface ObjCClass : Object
13
{
14
@public
15
  int info;
16
}
17
-(id) init;
18
-(id) initWithInformation: (int) whatInfo;
19
-(id) initWithInformation: (int) whatInfo andInfo: (int) info2;
20
@end
21
 
22
void foo(int info) {
23
   ObjCClass *mObj1 = [[ObjCClass alloc] init];
24
   ObjCClass *mObj2 = [[ObjCClass alloc] initWithInformation: info];
25
   ObjCClass *mObj3 = [[ObjCClass alloc] initWithInformation: info andInfo: 39];
26
 
27
   CHECK_IF(mObj1->info == 666);
28
   CHECK_IF(mObj2->info == info);
29
   CHECK_IF(mObj3->info == info + 39);
30
}
31
 
32
template 
33
class ObjCObjectWrapper
34
{
35
    public:
36
        ObjCObjectWrapper(int info);
37
        WrappedObjCClass *mObj1, *mObj2, *mObj3;
38
};
39
 
40
template 
41
ObjCObjectWrapper::ObjCObjectWrapper(int info)
42
{
43
    mObj1 = [[WrappedObjCClass alloc] init];
44
    mObj2 = [[WrappedObjCClass alloc] initWithInformation: info];
45
    mObj3 = [[WrappedObjCClass alloc] initWithInformation: info andInfo: 67];
46
}
47
 
48
@implementation ObjCClass
49
-(id) init {
50
  return [self initWithInformation:666];
51
}
52
-(id) initWithInformation: (int) whatInfo {
53
  [super init];
54
  info = whatInfo;
55
  return self;
56
}
57
-(id) initWithInformation: (int) whatInfo andInfo: (int) info2 {
58
  [super init];
59
  info = whatInfo + info2;
60
  return self;
61
}
62
@end
63
 
64
ObjCObjectWrapper staticInstance(42);
65
 
66
int main(void) {
67
  ObjCObjectWrapper stackInstance(47);
68
 
69
  foo(89);
70
 
71
  CHECK_IF(staticInstance.mObj1->info == 666);
72
  CHECK_IF(staticInstance.mObj2->info == 42);
73
  CHECK_IF(staticInstance.mObj3->info == 42 + 67);
74
 
75
  CHECK_IF(stackInstance.mObj1->info == 666);
76
  CHECK_IF(stackInstance.mObj2->info == 47);
77
  CHECK_IF(stackInstance.mObj3->info == 47 + 67);
78
 
79
  return 0;
80
}
81
#include "../objc-obj-c++-shared/Object1-implementation.h"

powered by: WebSVN 2.1.0

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