1
# Copyright 2002, 2003, 2004, 2007, 2008, 2009 Free Software Foundation, Inc.
1
# Copyright 2002, 2003, 2004, 2007, 2008, 2009, 2010
2
# Free Software Foundation, Inc.
3
4
# This program is free software; you can redistribute it and/or modify
4
5
# it under the terms of the GNU General Public License as published by
97
98
# Check compiler casting
98
99
gdb_test "print br" ".* = .B.* {<A> = {a = 42}, b = 1729}" \
99
100
"let compiler cast base class reference to derived class reference"
103
# A few basic tests of "new" casts.
105
gdb_test "print const_cast<const B *> (b)" " = \\(const B \\*\\) $hex" \
106
"basic test of const_cast"
108
gdb_test "print const_cast<void *> (0)" " = \\(void \\*\\) 0x0" \
111
gdb_test "print static_cast<A *> (b)" " = \\(A \\*\\) $hex" \
112
"basic test of static_cast"
114
gdb_test "print static_cast<A &> (*b)" " = \\(A \\&\\) @$hex: {a = 42}" \
115
"static_cast to reference type"
117
gdb_test "print reinterpret_cast<A *> (b)" " = \\(A \\*\\) $hex" \
118
"basic test of reinterpret_cast"
120
gdb_test "print reinterpret_cast<void> (b)" "Invalid reinterpret_cast" \
121
"test invalid reinterpret_cast"
123
gdb_test "print reinterpret_cast<A &> (*b)" " = \\(A \\&\\) @$hex: {a = 42}" \
124
"reinterpret_cast to reference type"
126
# Tests of dynamic_cast.
128
set nonzero_hex "0x\[0-9A-Fa-f\]\[0-9A-Fa-f\]+"
130
gdb_test "print dynamic_cast<void> (a)" \
131
".*must be a pointer or reference type" \
132
"invalid dynamic_cast"
134
gdb_test "print dynamic_cast<void *> (0)" \
135
" = \\(void \\*\\) 0x0" \
136
"dynamic_cast of 0 to void*"
138
gdb_test "print dynamic_cast<Alpha *> (&derived)" \
139
" = \\(Alpha \\*\\) $nonzero_hex" \
140
"dynamic_cast simple upcast"
142
gdb_test "print dynamic_cast<Alpha *> (&doublyderived)" \
143
" = \\(Alpha \\*\\) $nonzero_hex" \
144
"dynamic_cast upcast to unique base"
146
gdb_test "print dynamic_cast<Alpha &> (derived)" \
147
" = \\(Alpha \\&\\) @$nonzero_hex: {.* = $nonzero_hex}" \
148
"dynamic_cast simple upcast to reference"
150
gdb_test "print dynamic_cast<Derived *> (ad)" \
151
" = \\(Derived \\*\\) $nonzero_hex" \
152
"dynamic_cast simple downcast"
154
gdb_test "print dynamic_cast<VirtuallyDerived *> (add)" \
155
" = \\(VirtuallyDerived \\*\\) $nonzero_hex" \
156
"dynamic_cast simple downcast to intermediate class"
158
gdb_test "print dynamic_cast<VirtuallyDerived *> (ad)" \
159
" = \\(VirtuallyDerived \\*\\) 0x0" \
160
"dynamic_cast to non-existing base"
162
gdb_test "print dynamic_cast<VirtuallyDerived &> (*ad)" \
163
"dynamic_cast failed" \
164
"dynamic_cast to reference to non-existing base"
166
gdb_test "print dynamic_cast<DoublyDerived *> (add)" \
167
" = \\(DoublyDerived \\*\\) $nonzero_hex" \
168
"dynamic_cast unique downcast"
170
gdb_test "print dynamic_cast<Gamma *> (add)" \
171
" = \\(Gamma \\*\\) $nonzero_hex" \
172
"dynamic_cast to sibling"