aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.cp/ambiguous.exp
blob: b03eb8cad145c9f8638d7850f8691af5c407e578 (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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# Copyright 1998-1999, 2003-2004, 2007-2012 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/>.

# This file is part of the gdb testsuite

# tests relating to ambiguous class members
# Written by Satish Pai <pai@apollo.hp.com> 1997-07-28

# This file is part of the gdb testsuite

if $tracelevel then {
        strace $tracelevel
        }

#
# test running programs
#


if { [skip_cplus_tests] } { continue }

set testfile "ambiguous"
set srcfile ${testfile}.cc
set binfile ${objdir}/${subdir}/${testfile}

if [get_compiler_info ${binfile} "c++"] {
    return -1;
}

if { [test_compiler_info gcc-*] } then { continue }

if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
     untested ambiguous.exp
     return -1
}


gdb_exit
gdb_start
gdb_reinitialize_dir $srcdir/$subdir
gdb_load ${binfile}


#
# set it up at a breakpoint so we can play with the variable values
#
if ![runto_main] then {
    perror "couldn't run to breakpoint"
    continue
}

send_gdb "break marker1\n" ; gdb_expect -re ".*$gdb_prompt $"
    send_gdb "cont\n"
    gdb_expect {
        -re "Break.* marker1 \\(\\) at .*:$decimal.*$gdb_prompt $" {
            send_gdb "up\n"
            gdb_expect {
                -re ".*$gdb_prompt $" { pass "up from marker1" }
                timeout { fail "up from marker1" }
            }
        }
        -re "$gdb_prompt $" { fail "continue to marker1"  }
        timeout { fail "(timeout) continue to marker1"  }
    }

# print out various class objects' members.  The values aren't
# important, just check that the warning is emitted at the
# right times. 

# X is derived from A1 and A2; both A1 and A2 have a member 'x'
send_gdb "print x.x\n"
gdb_expect {
   -re "warning: x ambiguous; using X::A2::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
       pass "print x.x"
   }
   -re "warning: x ambiguous; using X::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
       pass "print x.x"
   }
   -re ".*$gdb_prompt $" { fail "print x.x" }
   timeout { fail "(timeout) print x.x" }
}


# N is derived from A1 and A2, but not immediately -- two steps
# up in the hierarchy. Both A1 and A2 have a member 'x'.
send_gdb "print n.x\n"
gdb_expect {
   -re "warning: x ambiguous; using N::M::A2::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
       pass "print n.x"
   }
   -re "warning: x ambiguous; using N::L::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
       pass "print n.x"
   }
   -re ".*$gdb_prompt $" { fail "print n.x" }
   timeout { fail "(timeout) print n.x" }
}

# J is derived from A1 twice.  A1 has a member x. 
send_gdb "print j.x\n"
gdb_expect {
   -re "warning: x ambiguous; using J::L::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
       pass "print j.x"
   }
   -re "warning: x ambiguous; using J::K::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
       pass "print j.x"
   }
   -re ".*$gdb_prompt $" { fail "print j.x" }
   timeout { fail "(timeout) print j.x" }
}

# JV is derived from A1 but A1 is a virtual base. Should not
# report an ambiguity in this case. 
send_gdb "print jv.x\n"
gdb_expect {
   -re "warning: x ambiguous.*Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
       fail "print jv.x (ambiguity reported)"
   }
   -re "\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" { pass "print jv.x" }
   -re ".*$gdb_prompt $" { fail "print jv.x (??)" }
   timeout { fail "(timeout) print jv.x" }
}

# JVA1 is derived from A1; A1 occurs as a virtual base in two
# ancestors, and as a non-virtual immediate base. Ambiguity must
# be reported. 
send_gdb "print jva1.x\n"
gdb_expect {
   -re "warning: x ambiguous; using JVA1::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
       pass "print jva1.x"
   }
   -re "warning: x ambiguous; using JVA1::KV::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
       pass "print jva1.x"
   }
   -re ".*$gdb_prompt $" { fail "print jva1.x" }
   timeout { fail "(timeout) print jva1.x" }
}

# JVA2 is derived from A1 & A2; A1 occurs as a virtual base in two
# ancestors, and A2 is a non-virtual immediate base. Ambiguity must
# be reported as A1 and A2 both have a member 'x'.
send_gdb "print jva2.x\n"
gdb_expect {
   -re "warning: x ambiguous; using JVA2::A2::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
       pass "print jva2.x"
   }
   -re "warning: x ambiguous; using JVA2::KV::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
       pass "print jva2.x"
   }
   -re ".*$gdb_prompt $" { fail "print jva2.x" }
   timeout { fail "(timeout) print jva2.x" }
}

# JVA1V is derived from A1; A1 occurs as a virtual base in two
# ancestors, and also as a virtual immediate base. Ambiguity must
# not be reported.
send_gdb "print jva1v.x\n"
gdb_expect {
   -re "warning: x ambiguous.*Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
       fail "print jva1v.x (ambiguity reported)"
   }
   -re "\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" { pass "print jva1v.x" }
   -re ".*$gdb_prompt $" { fail "print jva1v.x (??)" }
   timeout { fail "(timeout) print jva1v.x" }
}

# Now check for ambiguous bases.

# J is derived from A1 twice; report ambiguity if a J is
# cast to an A1.
send_gdb "print (A1)j\n"
gdb_expect {
   -re "warning: A1 ambiguous; using J::L::A1. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \{x = \[-\]*\[0-9\]*, y = \[-\]*\[0-9\]*\}\r\n$gdb_prompt $" {
       pass "print (A1)j"
   }
   -re "warning: A1 ambiguous; using J::K::A1. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \{x = \[-\]*\[0-9\]*, y = \[-\]*\[0-9\]*\}\r\n$gdb_prompt $" {
       pass "print (A1)j"
   }
   -re ".*$gdb_prompt $" { fail "print (A1)j" }
   timeout { fail "(timeout) print (A1)j" }
}

# JV is derived from A1 twice, but A1 is a virtual base; should
# not report ambiguity when a JV is cast to an A1.
send_gdb "print (A1)jv\n"
gdb_expect {
   -re "warning: A1 ambiguous.*Use a cast to disambiguate.\r\n\\$\[0-9\]* = \{x = \[-\]*\[0-9\]*, y = \[-\]*\[0-9\]*\}\r\n$gdb_prompt $" {
       fail "print (A1)jv (ambiguity reported)"
   }
   -re "\\$\[0-9\]* = \{x = \[-\]*\[0-9\]*, y = \[-\]*\[0-9\]*\}\r\n$gdb_prompt $" { pass "print (A1)jv" }
   -re ".*$gdb_prompt $" { fail "print (A1)jv (??)" }
   timeout { fail "(timeout) print (A1)jv" }
}

# JVA1 is derived from A1; A1 is a virtual base and also a
# non-virtual base.  Must report ambiguity if a JVA1 is cast to an A1.
send_gdb "print (A1)jva1\n"
gdb_expect {
   -re "warning: A1 ambiguous; using JVA1::A1. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \{x = \[-\]*\[0-9\]*, y = \[-\]*\[0-9\]*\}\r\n$gdb_prompt $" {
       pass "print (A1)jva1"
   }
   -re "warning: A1 ambiguous; using JVA1::KV::A1. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \{x = \[-\]*\[0-9\]*, y = \[-\]*\[0-9\]*\}\r\n$gdb_prompt $" {
       pass "print (A1)jva1"
   }
   -re ".*$gdb_prompt $" { fail "print (A1)jva1" }
   timeout { fail "(timeout) print (A1)jva1" }
}

# JVA1V is derived from A1; A1 is a virtual base indirectly
# and also directly; must not report ambiguity when a JVA1V is cast to an A1.
send_gdb "print (A1)jva1v\n"
gdb_expect {
   -re "warning: A1 ambiguous.*Use a cast to disambiguate.\r\n\\$\[0-9\]* = \{x = \[-\]*\[0-9\]*, y = \[-\]*\[0-9\]*\}\r\n$gdb_prompt $" {
       fail "print (A1)jva1v (ambiguity reported)"
   }
   -re "\\$\[0-9\]* = \{x = \[-\]*\[0-9\]*, y = \[-\]*\[0-9\]*\}\r\n$gdb_prompt $" { pass "print (A1)jva1v"
   }
   -re ".*$gdb_prompt $" { fail "print (A1)jva1v (??)" }
   timeout { fail "(timeout) print (A1)jva1v" }
}