aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.python/py-xmethods.cc
blob: 96637d8741f8cf5e3f1c243c13fe276fa5abef8d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/* This testcase is part of GDB, the GNU debugger.

   Copyright 2014 Free Software Foundation, Inc.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see  <http://www.gnu.org/licenses/>.  */

#include <iostream>

using namespace std;

namespace dop
{

class A
{
public:
  int a;
  int array [10];
  virtual ~A ();
  int operator+ (const A &obj);
  int operator- (const A &obj);
  virtual int geta (void);
};

A::~A () { }

int
A::operator+ (const A &obj)
{
  cout << "From CC <A_plus_A>:" << endl;
  return a + obj.a;
}

int
A::operator- (const A &obj)
{
  cout << "From CC <A_minus_A>:" << endl;
  return a - obj.a;
}

int
A::geta (void)
{
  cout << "From CC A::geta:" << endl;
  return a;
}

class B : public A
{
public:
  virtual int geta (void);
};

int
B::geta (void)
{
  cout << "From CC B::geta:" << endl;
  return 2 * a;
}

typedef B Bt;

typedef Bt Btt;

class E : public A
{
public:
  /* This class has a member named 'a', while the base class also has a
     member named 'a'.  When one invokes A::geta(), A::a should be
     returned and not E::a as the 'geta' method is defined on class 'A'.
     This class tests this aspect of debug methods.  */
  int a;
};

template <typename T>
class G
{
 public:
  template <typename T1>
  int size_diff ();

  template <int M>
  int size_mul ();

  template <typename T1>
  T mul(const T1 t1);

 public:
  T t;
};

template <typename T>
template <typename T1>
int
G<T>::size_diff ()
{
  cout << "From CC G<>::size_diff:" << endl;
  return sizeof (T1) - sizeof (T);
}

template <typename T>
template <int M>
int
G<T>::size_mul ()
{
  cout << "From CC G<>::size_mul:" << endl;
  return M * sizeof (T);
}

template <typename T>
template <typename T1>
T
G<T>::mul (const T1 t1)
{
  cout << "From CC G<>::mul:" << endl;
  return t1 * t;
}

}  // namespaxe dop

using namespace dop;

int main(void)
{
  A a1, a2;
  a1.a = 5;
  a2.a = 10;

  B b1;
  b1.a = 30;
  A *a_ptr = &b1;

  Bt bt;
  bt.a = 40;

  Btt btt;
  btt.a = -5;

  G<int> g, *g_ptr;
  g.t = 5;
  g_ptr = &g;

  E e;
  E &e_ref = e;
  E *e_ptr = &e;
  e.a = 1000;
  e.A::a = 100;

  int diff = g.size_diff<float> ();
  int smul = g.size_mul<2> ();
  int mul = g.mul (1.0);

  for (int i = 0; i < 10; i++)
    {
      a1.array[i] = a2.array[i] = i;
    }

  return 0; /* Break here.  */
}