2004-02-03 Michael Chastain <mec.gnu@mindspring.com>
[external/binutils.git] / gdb / testsuite / gdb.cp / virtfunc.exp
1 # Copyright 1992, 1994, 1995, 1996, 1997, 1998, 1999, 2001, 2002, 2003, 2004
2 # Free Software Foundation, Inc.
3
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
8
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
17
18 # Please email any bugs, comments, and/or additions to this file to:
19 # bug-gdb@prep.ai.mit.edu
20
21 # This file was written by Fred Fish. (fnf@cygnus.com)
22 # And rewritten by Michael Chastain <mec.gnu@mindspring.com>.
23
24 set wsopt       "\[\r\n\t \]*"
25 set ws          "\[\r\n\t \]+"
26 set nl          "\[\r\n\]+"
27
28 if $tracelevel then {
29     strace $tracelevel
30 }
31
32 if { [skip_cplus_tests] } { continue }
33
34 set testfile "virtfunc"
35 set srcfile ${testfile}.cc
36 set binfile ${objdir}/${subdir}/${testfile}
37
38 if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {c++ debug}] != "" } {
39      gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
40 }
41
42 # Test ptype of a class.
43 #
44 # Different C++ compilers produce different output.  I build up regular
45 # expressions piece by piece to accommodate all the compilers that I
46 # have seen: gcc 2.95.3, gcc 3.3.2 (ABI 1), gcc 3.4 prerelease (ABI 2);
47 # and all the debug formats I have seen: dwarf-2 and stabs+.
48 #
49 # A complicated class declaration looks like this:
50 #
51 #   class A : public virtual V {        // re_class
52 #     private:
53 #       V * _vb$V;                      // re_vbptr
54 #       int a;                          // re_fields
55 #
56 #     public:                           // re_access_methods
57 #       A & operator=(A const &);       // re_synth_gcc_2
58 #       A(int, A const &);              // ...
59 #       A(int);                         // ...
60 #       virtual int f(void);            // re_methods
61 #   }
62 #
63 # RE_CLASS matches the class declaration.  C++ allows multiple ways of
64 # expressing this.
65 #
66 #   struct ... { private: ... };
67 #   class ... { private: ... };
68 #   class ... { ... };
69 #
70 # RE_VBPTR matches the virtual base declarations.  gcc 2.95.3 sometimes
71 # emits these, but gcc 3.X.Y never emits these.  The name depends on the
72 # debug format.
73 #
74 # RE_FIELDS matches the data fields of the class.
75 # RE_METHODS matches the methods explicitly declared for the class.
76 #
77 # RE_SYNTH_GCC_2 and RE_SYNTH_GCC_3 match the optional synthetic methods
78 # of the class.  gcc -gstabs+ emits these methods, and gcc -gdwarf-2
79 # does not.
80 #
81 # RE_ACCESS_METHODS is an access specifier after RE_FIELDS and before
82 # the methods (explicit methods and/or synthetic methods).
83 # There is also an RE_ACCESS_FIELDS.
84 #
85 # When I get HP-UX aCC, I hope that I can just add RE_SYNTH_ACC_NNN.
86 #
87 # Yet another twist: with gcc v2, ctor and dtor methods have a hidden
88 # argument in front, the "in-charge" flag.  With gcc v3, there is no
89 # hidden argument; instead, there are multiple object functions for
90 # each ctor and dtor.
91 #
92 # -- chastain 2004-01-01
93
94 proc test_one_ptype { command testname re_class re_vbptr re_access_fields re_fields re_access_methods re_methods re_synth_gcc_2 re_synth_gcc_3 re_star } {
95     global gdb_prompt
96     global wsopt
97     global ws
98     global nl
99
100     gdb_test_multiple "$command" "$testname" {
101         -re "type = $re_class${wsopt}$re_access_fields${wsopt}$re_fields${wsopt}$re_access_methods${wsopt}$re_methods$nl\}$re_star$nl$gdb_prompt $" {
102             # gcc 2.95.3, dwarf-2, no vbptr
103             # gcc 3.X, abi 1, dwarf-2
104             # gcc 3.X, abi 2, dwarf-2
105             pass "$testname"
106         }
107         -re "type = $re_class${wsopt}$re_vbptr${wsopt}$re_access_fields${wsopt}$re_fields${wsopt}$re_access_methods${wsopt}$re_methods$nl\}$re_star$nl$gdb_prompt $" {
108             # gcc 2.95.3, dwarf-2, vbptr
109             # TODO: drow says the vbptr is a bug
110             pass "$testname"
111         }
112         -re "type = $re_class${wsopt}$re_access_fields${wsopt}$re_fields${wsopt}$re_access_methods${wsopt}$re_synth_gcc_2${wsopt}$re_methods$nl\}$re_star$nl$gdb_prompt $" {
113             # gcc 2.95.3, stabs+, no vbptr
114             pass "$testname"
115         }
116         -re "type = $re_class${wsopt}$re_vbptr${wsopt}$re_access_fields${wsopt}$re_fields${wsopt}$re_access_methods${wsopt}$re_synth_gcc_2${wsopt}$re_methods$nl\}$re_star$nl$gdb_prompt $" {
117             # gcc 2.95.3, stabs+, vbptr
118             # TODO: drow says the vbptr is a bug
119             pass "$testname"
120         }
121         -re "type = $re_class${wsopt}$re_access_fields${wsopt}$re_fields${wsopt}$re_access_methods${wsopt}$re_synth_gcc_3${wsopt}$re_methods$nl\}$re_star$nl$gdb_prompt $" {
122             # gcc 3.X, abi 1, stabs+
123             pass "$testname"
124         }
125         -re "type = $re_class${wsopt}$re_access_fields${wsopt}$re_fields${wsopt}$re_access_methods${wsopt}$re_methods${wsopt}$re_synth_gcc_3$nl\}$re_star$nl$gdb_prompt $" {
126             # gcc 3.X, abi 2, stabs+
127             pass "$testname"
128         }
129     }
130
131 }
132
133 proc test_ptype_of_classes {} {
134     global gdb_prompt
135     global ws
136     global nl
137
138     # class VA
139
140     test_one_ptype "ptype VA" "ptype VA" \
141         "((struct|class) VA \{${ws}public:|struct VA \{)" \
142         "" \
143         "" "int va;" \
144         "" "" \
145         "VA & operator=\\(VA const ?&\\);${ws}VA\\(VA const ?&\\);${ws}VA\\((void|)\\);" \
146         "VA & operator=\\(VA const ?&\\);${ws}VA\\(VA const ?&\\);${ws}VA\\((void|)\\);" \
147         ""
148
149     # class VB
150
151     test_one_ptype "ptype VB" "ptype VB" \
152         "((struct|class) VB \{${ws}public:|struct VB \{)" \
153         "" \
154         "" "int vb;" \
155         "" "int fvb\\((void|)\\);${ws}virtual int vvb\\((void|)\\);" \
156         "VB & operator=\\(VB const ?&\\);${ws}VB\\(VB const ?&\\);${ws}VB\\((void|)\\);" \
157         "VB & operator=\\(VB const ?&\\);${ws}VB\\(VB const ?&\\);${ws}VB\\((void|)\\);" \
158         ""
159
160     # class V
161
162     test_one_ptype "ptype V" "ptype V" \
163         "class V : public VA, public VB \{${ws}public:" \
164         "" \
165         "" "int w;" \
166         "" "int f\\((void|)\\);${ws}virtual int vv\\((void|)\\);" \
167         "V & operator=\\(V const ?&\\);${ws}V\\(V const ?&\\);${ws}V\\((void|)\\);" \
168         "V & operator=\\(V const ?&\\);${ws}V\\(V const ?&\\);${ws}V\\((void|)\\);" \
169         ""
170
171     # class A
172
173     test_one_ptype "ptype A" "ptype A" \
174         "class A : public virtual V \{(${ws}private:|)" \
175         "V \\*(_vb.1V|_vb.V);" \
176         "" "int a;" \
177         "public:" "virtual int f\\((void|)\\);" \
178         "A & operator=\\(A const ?&\\);${ws}A\\(int, A const ?&\\);${ws}A\\(int\\);" \
179         "A & operator=\\(A const ?&\\);${ws}A\\(A const ?&\\);${ws}A\\((void|)\\);" \
180         ""
181
182     # class B
183
184     test_one_ptype "ptype B" "ptype B" \
185         "class B : public A \{(${ws}private:|)" \
186         "V \\*(_vb.1V|_vb.V);" \
187         "" "int b;" \
188         "public:" "virtual int f\\((void|)\\);" \
189         "B & operator=\\(B const ?&\\);${ws}B\\(int, B const ?&\\);${ws}B\\(int\\);" \
190         "B & operator=\\(B const ?&\\);${ws}B\\(B const ?&\\);${ws}B\\((void|)\\);" \
191         ""
192
193     # class C
194
195     test_one_ptype "ptype C" "ptype C" \
196         "class C : public virtual V \{(${ws}private:|)" \
197         "V \\*(_vb.1V|_vb.V);" \
198         "public:" "int c;" \
199         "" "" \
200         "C & operator=\\(C const ?&\\);${ws}C\\(int, C const ?&\\);${ws}C\\(int\\);" \
201         "C & operator=\\(C const ?&\\);${ws}C\\(C const ?&\\);${ws}C\\((void|)\\);" \
202         ""
203
204     # class AD
205
206     test_one_ptype "ptype AD" "ptype AD" \
207         "((struct|class) AD \{${ws}public:|struct AD \{)" \
208         "" \
209         "" "" \
210         "" "virtual int vg\\((void|)\\);" \
211         "AD & operator=\\(AD const ?&\\);${ws}AD\\(AD const ?&\\);${ws}AD\\((void|)\\);" \
212         "AD & operator=\\(AD const ?&\\);${ws}AD\\(AD const ?&\\);${ws}AD\\((void|)\\);" \
213         ""
214
215     # class D
216
217     test_one_ptype "ptype D" "ptype D" \
218         "class D : public AD, public virtual V \{(${ws}private:|)" \
219         "V \\*(_vb.1V|_vb.V);" \
220         "public:" "int d;" \
221         "" "static void s\\((void|)\\);${ws}virtual int vg\\((void|)\\);${ws}virtual int vd\\((void|)\\);${ws}int fd\\((void|)\\);" \
222         "D & operator=\\(D const ?&\\);${ws}D\\(int, D const ?&\\);${ws}D\\(int\\);" \
223         "D & operator=\\(D const ?&\\);${ws}D\\(D const ?&\\);${ws}D\\((void|)\\);" \
224         ""
225
226     # class E
227     # TODO: E does not show a vbptr for V.  That seems strange.
228
229     test_one_ptype "ptype E" "ptype E" \
230         "class E : public B, public virtual V, public D, public C \{(${ws}private:|)" \
231         "" \
232         "public:" "int e;" \
233         "" "virtual int f\\((void|)\\);${ws}virtual int vg\\((void|)\\);${ws}virtual int vv\\((void|)\\);" \
234         "E & operator=\\(E const ?&\\);${ws}E\\(int, E const ?&\\);${ws}E\\(int\\);" \
235         "E & operator=\\(E const ?&\\);${ws}E\\(E const ?&\\);${ws}E\\((void|)\\);" \
236         ""
237
238     # An instance of D
239
240     test_one_ptype "ptype dd" "ptype dd" \
241         "class D : public AD, public virtual V \{(${ws}private:|)" \
242         "V \\*(_vb.1V|_vb.V);" \
243         "public:" "int d;" \
244         "" "static void s\\((void|)\\);${ws}virtual int vg\\((void|)\\);${ws}virtual int vd\\((void|)\\);${ws}int fd\\((void|)\\);" \
245         "D & operator=\\(D const ?&\\);${ws}D\\(int, D const ?&\\);${ws}D\\(int\\);" \
246         "D & operator=\\(D const ?&\\);${ws}D\\(D const ?&\\);${ws}D\\((void|)\\);" \
247         ""
248
249     # An instance of D *
250
251     test_one_ptype "ptype ppd" "ptype ppd" \
252         "class D : public AD, public virtual V \{(${ws}private:|)" \
253         "V \\*(_vb.1V|_vb.V);" \
254         "public:" "int d;" \
255         "" "static void s\\((void|)\\);${ws}virtual int vg\\((void|)\\);${ws}virtual int vd\\((void|)\\);${ws}int fd\\((void|)\\);" \
256         "D & operator=\\(D const ?&\\);${ws}D\\(int, D const ?&\\);${ws}D\\(int\\);" \
257         "D & operator=\\(D const ?&\\);${ws}D\\(D const ?&\\);${ws}D\\((void|)\\);" \
258         " ?\\*"
259
260     # An instance of AD *
261     # TODO: this should be named pADd, not pAd.
262
263     test_one_ptype "ptype pAd" "ptype pAd" \
264         "((struct|class) AD \{${ws}public:|struct AD \{)" \
265         "" \
266         "" "" \
267         "" "virtual int vg\\((void|)\\);" \
268         "AD & operator=\\(AD const ?&\\);${ws}AD\\(AD const ?&\\);${ws}AD\\((void|)\\);" \
269         "AD & operator=\\(AD const ?&\\);${ws}AD\\(AD const ?&\\);${ws}AD\\((void|)\\);" \
270         " ?\\*"
271
272     # An instance of A
273
274     test_one_ptype "ptype a" "ptype a" \
275         "class A : public virtual V \{(${ws}private:|)" \
276         "V \\*(_vb.1V|_vb.V);" \
277         "" "int a;" \
278         "public:" "virtual int f\\((void|)\\);" \
279         "A & operator=\\(A const ?&\\);${ws}A\\(int, A const ?&\\);${ws}A\\(int\\);" \
280         "A & operator=\\(A const ?&\\);${ws}A\\(A const ?&\\);${ws}A\\((void|)\\);" \
281         ""
282
283     # An instance of B
284
285     test_one_ptype "ptype b" "ptype b" \
286         "class B : public A \{(${ws}private:|)" \
287         "V \\*(_vb.1V|_vb.V);" \
288         "" "int b;" \
289         "public:" "virtual int f\\((void|)\\);" \
290         "B & operator=\\(B const ?&\\);${ws}B\\(int, B const ?&\\);${ws}B\\(int\\);" \
291         "B & operator=\\(B const ?&\\);${ws}B\\(B const ?&\\);${ws}B\\((void|)\\);" \
292         ""
293
294     # An instance of C
295
296     test_one_ptype "ptype c" "ptype c" \
297         "class C : public virtual V \{(${ws}private:|)" \
298         "V \\*(_vb.1V|_vb.V);" \
299         "public:" "int c;" \
300         "" "" \
301         "C & operator=\\(C const ?&\\);${ws}C\\(int, C const ?&\\);${ws}C\\(int\\);" \
302         "C & operator=\\(C const ?&\\);${ws}C\\(C const ?&\\);${ws}C\\((void|)\\);" \
303         ""
304
305     # An instance of D
306
307     test_one_ptype "ptype d" "ptype d" \
308         "class D : public AD, public virtual V \{(${ws}private:|)" \
309         "V \\*(_vb.1V|_vb.V);" \
310         "public:" "int d;" \
311         "" "static void s\\((void|)\\);${ws}virtual int vg\\((void|)\\);${ws}virtual int vd\\((void|)\\);${ws}int fd\\((void|)\\);" \
312         "D & operator=\\(D const ?&\\);${ws}D\\(int, D const ?&\\);${ws}D\\(int\\);" \
313         "D & operator=\\(D const ?&\\);${ws}D\\(D const ?&\\);${ws}D\\((void|)\\);" \
314         ""
315
316     # An instance of E
317
318     test_one_ptype "ptype e" "ptype e" \
319         "class E : public B, public virtual V, public D, public C \{(${ws}private:|)" \
320         "" \
321         "public:" "int e;" \
322         "" "virtual int f\\((void|)\\);${ws}virtual int vg\\((void|)\\);${ws}virtual int vv\\((void|)\\);" \
323         "E & operator=\\(E const ?&\\);${ws}E\\(int, E const ?&\\);${ws}E\\(int\\);" \
324         "E & operator=\\(E const ?&\\);${ws}E\\(E const ?&\\);${ws}E\\((void|)\\);" \
325         ""
326
327     # An instance of V
328
329     test_one_ptype "ptype v" "ptype v" \
330         "class V : public VA, public VB \{${ws}public:" \
331         "" \
332         "" "int w;" \
333         "" "int f\\((void|)\\);${ws}virtual int vv\\((void|)\\);" \
334         "V & operator=\\(V const ?&\\);${ws}V\\(V const ?&\\);${ws}V\\((void|)\\);" \
335         "V & operator=\\(V const ?&\\);${ws}V\\(V const ?&\\);${ws}V\\((void|)\\);" \
336         ""
337
338     # An instance of VB
339
340     test_one_ptype "ptype vb" "ptype vb" \
341         "((struct|class) VB \{${ws}public:|struct VB \{)" \
342         "" \
343         "" "int vb;" \
344         "" "int fvb\\((void|)\\);${ws}virtual int vvb\\((void|)\\);" \
345         "VB & operator=\\(VB const ?&\\);${ws}VB\\(VB const ?&\\);${ws}VB\\((void|)\\);" \
346         "VB & operator=\\(VB const ?&\\);${ws}VB\\(VB const ?&\\);${ws}VB\\((void|)\\);" \
347         ""
348
349     # An instance of A *
350
351     test_one_ptype "ptype pAa" "ptype pAa" \
352         "class A : public virtual V \{(${ws}private:|)" \
353         "V \\*(_vb.1V|_vb.V);" \
354         "" "int a;" \
355         "public:" "virtual int f\\((void|)\\);" \
356         "A & operator=\\(A const ?&\\);${ws}A\\(int, A const ?&\\);${ws}A\\(int\\);" \
357         "A & operator=\\(A const ?&\\);${ws}A\\(A const ?&\\);${ws}A\\((void|)\\);" \
358         " ?\\*"
359
360     # An instance of A *
361
362     test_one_ptype "ptype pAe" "ptype pAe" \
363         "class A : public virtual V \{(${ws}private:|)" \
364         "V \\*(_vb.1V|_vb.V);" \
365         "" "int a;" \
366         "public:" "virtual int f\\((void|)\\);" \
367         "A & operator=\\(A const ?&\\);${ws}A\\(int, A const ?&\\);${ws}A\\(int\\);" \
368         "A & operator=\\(A const ?&\\);${ws}A\\(A const ?&\\);${ws}A\\((void|)\\);" \
369         " ?\\*"
370
371     # An instance of B *
372
373     test_one_ptype "ptype pBe" "ptype pBe" \
374         "class B : public A \{(${ws}private:|)" \
375         "V \\*(_vb.1V|_vb.V);" \
376         "" "int b;" \
377         "public:" "virtual int f\\((void|)\\);" \
378         "B & operator=\\(B const ?&\\);${ws}B\\(int, B const ?&\\);${ws}B\\(int\\);" \
379         "B & operator=\\(B const ?&\\);${ws}B\\(B const ?&\\);${ws}B\\((void|)\\);" \
380         " ?\\*"
381
382     # An instance of D *
383
384     test_one_ptype "ptype pDd" "ptype pDd" \
385         "class D : public AD, public virtual V \{(${ws}private:|)" \
386         "V \\*(_vb.1V|_vb.V);" \
387         "public:" "int d;" \
388         "" "static void s\\((void|)\\);${ws}virtual int vg\\((void|)\\);${ws}virtual int vd\\((void|)\\);${ws}int fd\\((void|)\\);" \
389         "D & operator=\\(D const ?&\\);${ws}D\\(int, D const ?&\\);${ws}D\\(int\\);" \
390         "D & operator=\\(D const ?&\\);${ws}D\\(D const ?&\\);${ws}D\\((void|)\\);" \
391         " ?\\*"
392
393     # An instance of D *
394
395     test_one_ptype "ptype pDe" "ptype pDe" \
396         "class D : public AD, public virtual V \{(${ws}private:|)" \
397         "V \\*(_vb.1V|_vb.V);" \
398         "public:" "int d;" \
399         "" "static void s\\((void|)\\);${ws}virtual int vg\\((void|)\\);${ws}virtual int vd\\((void|)\\);${ws}int fd\\((void|)\\);" \
400         "D & operator=\\(D const ?&\\);${ws}D\\(int, D const ?&\\);${ws}D\\(int\\);" \
401         "D & operator=\\(D const ?&\\);${ws}D\\(D const ?&\\);${ws}D\\((void|)\\);" \
402         " ?\\*"
403
404     # An instance of V *
405
406     test_one_ptype "ptype pVa" "ptype pVa" \
407         "class V : public VA, public VB \{${ws}public:" \
408         "" \
409         "" "int w;" \
410         "" "int f\\((void|)\\);${ws}virtual int vv\\((void|)\\);" \
411         "V & operator=\\(V const ?&\\);${ws}V\\(V const ?&\\);${ws}V\\((void|)\\);" \
412         "V & operator=\\(V const ?&\\);${ws}V\\(V const ?&\\);${ws}V\\((void|)\\);" \
413         " ?\\*"
414
415     # An instance of V *
416
417     test_one_ptype "ptype pVv" "ptype pVv" \
418         "class V : public VA, public VB \{${ws}public:" \
419         "" \
420         "" "int w;" \
421         "" "int f\\((void|)\\);${ws}virtual int vv\\((void|)\\);" \
422         "V & operator=\\(V const ?&\\);${ws}V\\(V const ?&\\);${ws}V\\((void|)\\);" \
423         "V & operator=\\(V const ?&\\);${ws}V\\(V const ?&\\);${ws}V\\((void|)\\);" \
424         " ?\\*"
425
426     # An instance of V *
427
428     test_one_ptype "ptype pVe" "ptype pVe" \
429         "class V : public VA, public VB \{${ws}public:" \
430         "" \
431         "" "int w;" \
432         "" "int f\\((void|)\\);${ws}virtual int vv\\((void|)\\);" \
433         "V & operator=\\(V const ?&\\);${ws}V\\(V const ?&\\);${ws}V\\((void|)\\);" \
434         "V & operator=\\(V const ?&\\);${ws}V\\(V const ?&\\);${ws}V\\((void|)\\);" \
435         " ?\\*"
436
437     # An instance of V *
438
439     test_one_ptype "ptype pVd" "ptype pVd" \
440         "class V : public VA, public VB \{${ws}public:" \
441         "" \
442         "" "int w;" \
443         "" "int f\\((void|)\\);${ws}virtual int vv\\((void|)\\);" \
444         "V & operator=\\(V const ?&\\);${ws}V\\(V const ?&\\);${ws}V\\((void|)\\);" \
445         "V & operator=\\(V const ?&\\);${ws}V\\(V const ?&\\);${ws}V\\((void|)\\);" \
446         " ?\\*"
447
448     # An instance of AD *
449
450     test_one_ptype "ptype pADe" "ptype pADe" \
451         "((struct|class) AD \{${ws}public:|struct AD \{)" \
452         "" \
453         "" "" \
454         "" "virtual int vg\\((void|)\\);" \
455         "AD & operator=\\(AD const ?&\\);${ws}AD\\(AD const ?&\\);${ws}AD\\((void|)\\);" \
456         "AD & operator=\\(AD const ?&\\);${ws}AD\\(AD const ?&\\);${ws}AD\\((void|)\\);" \
457         " ?\\*"
458
459     # An instance of E *
460
461     test_one_ptype "ptype pEe" "ptype pEe" \
462         "class E : public B, public virtual V, public D, public C \{(${ws}private:|)" \
463         "" \
464         "public:" "int e;" \
465         "" "virtual int f\\((void|)\\);${ws}virtual int vg\\((void|)\\);${ws}virtual int vv\\((void|)\\);" \
466         "E & operator=\\(E const ?&\\);${ws}E\\(int, E const ?&\\);${ws}E\\(int\\);" \
467         "E & operator=\\(E const ?&\\);${ws}E\\(E const ?&\\);${ws}E\\((void|)\\);" \
468         " ?\\*"
469
470     # An instance of VB *
471
472     test_one_ptype "ptype pVB" "ptype pVB" \
473         "((struct|class) VB \{${ws}public:|struct VB \{)" \
474         "" \
475         "" "int vb;" \
476         "" "int fvb\\((void|)\\);${ws}virtual int vvb\\((void|)\\);" \
477         "VB & operator=\\(VB const ?&\\);${ws}VB\\(VB const ?&\\);${ws}VB\\((void|)\\);" \
478         "VB & operator=\\(VB const ?&\\);${ws}VB\\(VB const ?&\\);${ws}VB\\((void|)\\);" \
479         " ?\\*"
480 }
481
482 # Call virtual functions.
483
484 proc test_virtual_calls {} {
485     global gdb_prompt
486     global nl
487
488     if [target_info exists gdb,cannot_call_functions] {
489         setup_xfail "*-*-*" 2416
490         fail "This target can not call functions"
491         return 0
492     }
493
494     gdb_test "print pAe->f()"   "\\$\[0-9\]+ = 20"
495     gdb_test "print pAa->f()"   "\\$\[0-9\]+ = 1"
496     gdb_test "print pDe->vg()"  "\\$\[0-9\]+ = 202"
497     gdb_test "print pADe->vg()" "\\$\[0-9\]+ = 202"
498     gdb_test "print pDd->vg()"  "\\$\[0-9\]+ = 101"
499     gdb_test "print pEe->vvb()" "\\$\[0-9\]+ = 411"
500     gdb_test "print pVB->vvb()" "\\$\[0-9\]+ = 407"
501     gdb_test "print pBe->vvb()" "\\$\[0-9\]+ = 411"
502     gdb_test "print pDe->vvb()" "\\$\[0-9\]+ = 411"
503     gdb_test "print pEe->vd()"  "\\$\[0-9\]+ = 282"
504     gdb_test "print pEe->fvb()" "\\$\[0-9\]+ = 311"
505
506     # more recent results:
507     # wrong value "202"
508     #   gcc 2.95.3 -gdwarf-2
509     #   gcc 2.95.3 -gstabs+
510     # attempt to take addres of value not located in memory
511     #   gcc 3.3.2 -gdwarf-2
512     #   gcc 3.3.2 -gstabs+
513     #
514     # -- chastain 2003-12-31
515
516     gdb_test_multiple "print pEe->D::vg()" "print pEe->D::vg()" {
517         -re "\\$\[0-9]+ = 102$nl$gdb_prompt $" {
518             pass "print pEe->D::vg()"
519         }
520         -re "Attempt to take address of value not located in memory.$nl$gdb_prompt $" {
521             kfail "gdb/1064" "print pEe->D::vg()"
522         }
523     }
524 }
525
526 proc do_tests {} {
527     global prms_id
528     global bug_id
529     global srcdir subdir binfile
530     global gdb_prompt
531
532     set prms_id 0
533     set bug_id 0
534
535     gdb_exit
536     gdb_start
537     gdb_reinitialize_dir $srcdir/$subdir
538     gdb_load $binfile
539
540     gdb_test "set language c++" "" ""
541     gdb_test "set width 0" "" ""
542
543     runto_main
544     test_ptype_of_classes
545
546     gdb_breakpoint test_calls
547     gdb_test "continue" ".*Breakpoint .* test_calls.*" ""
548     test_virtual_calls
549 }
550
551 do_tests