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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [g++.dg/] [torture/] [pr49519.C] - Blame information for rev 701

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 693 jeremybenn
/* { dg-do run } */
2
 
3
#include 
4
 
5
struct null_type {};
6
 
7
inline const null_type cnull() { return null_type(); }
8
 
9
template  struct cons;
10
class tuple;
11
 
12
template< int N >
13
struct get_class {
14
  template
15
  inline static int& get(cons& t)
16
  {
17
    return get_class::template get(t.tail);
18
  }
19
};
20
 
21
template<>
22
struct get_class<0> {
23
  template
24
  inline static int& get(cons& t)
25
  {
26
    return t.head;
27
  }
28
};
29
 
30
template
31
struct element
32
{
33
private:
34
  typedef typename T::tail_type Next;
35
public:
36
  typedef typename element::type type;
37
};
38
 
39
template
40
struct element<0,T>
41
{
42
  typedef int type;
43
};
44
 
45
template
46
inline int& get(cons& c) {
47
  return get_class::template get(c);
48
}
49
 
50
template 
51
struct cons {
52
  typedef TT tail_type;
53
 
54
  int head;
55
  tail_type tail;
56
 
57
  cons() : head(), tail() {}
58
 
59
  template 
60
  cons( T1& t1, T2& t2, T3& t3, T4& t4 )
61
    : head (t1),
62
      tail (t2, t3, t4, cnull())
63
      {}
64
};
65
 
66
template <>
67
struct cons {
68
  typedef null_type tail_type;
69
 
70
  int head;
71
 
72
  cons() : head() {}
73
 
74
  template
75
  cons(T1& t1, const null_type&, const null_type&, const null_type&)
76
  : head (t1) {}
77
};
78
 
79
template 
80
struct map_tuple_to_cons
81
{
82
  typedef cons::type> type;
83
};
84
 
85
template <>
86
struct map_tuple_to_cons
87
{
88
  typedef null_type type;
89
};
90
 
91
class tuple :
92
  public map_tuple_to_cons::type
93
{
94
public:
95
  typedef typename
96
    map_tuple_to_cons::type inherited;
97
 
98
  tuple(const int &t0,
99
        const int &t1,
100
        const int &t2,
101
        const int &t3)
102
    : inherited(t0, t1, t2, t3) {}
103
};
104
 
105
void foo(void (*boo)(int, int, int, int), tuple t)
106
{
107
  boo(get<0>(t), get<1>(t), get<2>(t), get<3>(t));
108
}
109
 
110
int tailcalled_t1;
111
int tailcalled_t2;
112
int tailcalled_t3;
113
int tailcalled_t4;
114
 
115
void print(int t1, int t2, int t3, int t4)
116
{
117
  tailcalled_t1 = t1;
118
  tailcalled_t2 = t2;
119
  tailcalled_t3 = t3;
120
  tailcalled_t4 = t4;
121
}
122
 
123
int main ()
124
{
125
  tuple t(1,2,3,4);
126
  foo(print, t);
127
 
128
  if( (get<0>(t) != tailcalled_t1)
129
    ||(get<1>(t) != tailcalled_t2)
130
    ||(get<2>(t) != tailcalled_t3)
131
      ||(get<3>(t) != tailcalled_t4))
132
      abort();
133
 
134
  return 0;
135
}

powered by: WebSVN 2.1.0

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