Commit | Line | Data |
---|---|---|
883964a7 SC |
1 | /* This testcase is part of GDB, the GNU debugger. |
2 | ||
42a4f53d | 3 | Copyright 2014-2019 Free Software Foundation, Inc. |
883964a7 SC |
4 | |
5 | This program is free software; you can redistribute it and/or modify | |
6 | it under the terms of the GNU General Public License as published by | |
7 | the Free Software Foundation; either version 3 of the License, or | |
8 | (at your option) any later version. | |
9 | ||
10 | This program is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | GNU General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU General Public License | |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
17 | ||
883964a7 SC |
18 | namespace dop |
19 | { | |
20 | ||
21 | class A | |
22 | { | |
23 | public: | |
24 | int a; | |
25 | int array [10]; | |
26 | virtual ~A (); | |
27 | int operator+ (const A &obj); | |
28 | int operator- (const A &obj); | |
29 | virtual int geta (void); | |
30 | }; | |
31 | ||
32 | A::~A () { } | |
33 | ||
5d376983 SC |
34 | int a_plus_a = 0; |
35 | ||
883964a7 SC |
36 | int |
37 | A::operator+ (const A &obj) | |
38 | { | |
5d376983 | 39 | a_plus_a++; |
883964a7 SC |
40 | return a + obj.a; |
41 | } | |
42 | ||
5d376983 SC |
43 | int a_minus_a = 0; |
44 | ||
883964a7 SC |
45 | int |
46 | A::operator- (const A &obj) | |
47 | { | |
5d376983 | 48 | a_minus_a++; |
883964a7 SC |
49 | return a - obj.a; |
50 | } | |
51 | ||
5d376983 SC |
52 | int a_geta = 0; |
53 | ||
883964a7 SC |
54 | int |
55 | A::geta (void) | |
56 | { | |
5d376983 | 57 | a_geta++; |
883964a7 SC |
58 | return a; |
59 | } | |
60 | ||
61 | class B : public A | |
62 | { | |
63 | public: | |
64 | virtual int geta (void); | |
65 | }; | |
66 | ||
5d376983 SC |
67 | int b_geta = 0; |
68 | ||
883964a7 SC |
69 | int |
70 | B::geta (void) | |
71 | { | |
5d376983 | 72 | b_geta++; |
883964a7 SC |
73 | return 2 * a; |
74 | } | |
75 | ||
76 | typedef B Bt; | |
77 | ||
78 | typedef Bt Btt; | |
79 | ||
80 | class E : public A | |
81 | { | |
82 | public: | |
83 | /* This class has a member named 'a', while the base class also has a | |
84 | member named 'a'. When one invokes A::geta(), A::a should be | |
85 | returned and not E::a as the 'geta' method is defined on class 'A'. | |
86 | This class tests this aspect of debug methods. */ | |
87 | int a; | |
88 | }; | |
89 | ||
90 | template <typename T> | |
91 | class G | |
92 | { | |
93 | public: | |
94 | template <typename T1> | |
95 | int size_diff (); | |
96 | ||
97 | template <int M> | |
98 | int size_mul (); | |
99 | ||
100 | template <typename T1> | |
101 | T mul(const T1 t1); | |
102 | ||
103 | public: | |
104 | T t; | |
105 | }; | |
106 | ||
5d376983 SC |
107 | int g_size_diff = 0; |
108 | ||
883964a7 SC |
109 | template <typename T> |
110 | template <typename T1> | |
111 | int | |
112 | G<T>::size_diff () | |
113 | { | |
5d376983 | 114 | g_size_diff++; |
883964a7 SC |
115 | return sizeof (T1) - sizeof (T); |
116 | } | |
117 | ||
5d376983 SC |
118 | int g_size_mul = 0; |
119 | ||
883964a7 SC |
120 | template <typename T> |
121 | template <int M> | |
122 | int | |
123 | G<T>::size_mul () | |
124 | { | |
5d376983 | 125 | g_size_mul++; |
883964a7 SC |
126 | return M * sizeof (T); |
127 | } | |
128 | ||
5d376983 SC |
129 | int g_mul = 0; |
130 | ||
883964a7 SC |
131 | template <typename T> |
132 | template <typename T1> | |
133 | T | |
134 | G<T>::mul (const T1 t1) | |
135 | { | |
5d376983 | 136 | g_mul++; |
883964a7 SC |
137 | return t1 * t; |
138 | } | |
139 | ||
140 | } // namespaxe dop | |
141 | ||
142 | using namespace dop; | |
143 | ||
144 | int main(void) | |
145 | { | |
146 | A a1, a2; | |
147 | a1.a = 5; | |
148 | a2.a = 10; | |
149 | ||
150 | B b1; | |
151 | b1.a = 30; | |
152 | A *a_ptr = &b1; | |
153 | ||
154 | Bt bt; | |
155 | bt.a = 40; | |
156 | ||
157 | Btt btt; | |
158 | btt.a = -5; | |
159 | ||
160 | G<int> g, *g_ptr; | |
161 | g.t = 5; | |
162 | g_ptr = &g; | |
163 | ||
164 | E e; | |
165 | E &e_ref = e; | |
166 | E *e_ptr = &e; | |
167 | e.a = 1000; | |
168 | e.A::a = 100; | |
169 | ||
170 | int diff = g.size_diff<float> (); | |
171 | int smul = g.size_mul<2> (); | |
172 | int mul = g.mul (1.0); | |
173 | ||
174 | for (int i = 0; i < 10; i++) | |
175 | { | |
4c082a81 | 176 | a1.array[i] = a2.array[i] = b1.array[i] = i; |
883964a7 SC |
177 | } |
178 | ||
179 | return 0; /* Break here. */ | |
180 | } |