* gdb.cp/casts.cc: Add class reference variables.

* gdb.cp/casts.exp: New test cases for up/down casting references.
This commit is contained in:
Aleksandar Ristovski 2008-04-01 16:16:43 +00:00
parent 6af87b0348
commit f0050c2089
2 changed files with 19 additions and 0 deletions

View file

@ -15,6 +15,8 @@ main (int argc, char **argv)
{
A *a = new B(42, 1729);
B *b = (B *) a;
A &ar = *b;
B &br = (B&)ar;
return 0; /* breakpoint spot: casts.exp: 1 */
}

View file

@ -80,3 +80,20 @@ gdb_test "print * (B *) a" ".* = {<A> = {a = 42}, b = 1729}" \
# the dereference.
gdb_test "print * b" ".* = {<A> = {a = 42}, b = 1729}" \
"let compiler cast base class pointer to derived class pointer"
# Check upcasting (it is trivial but still).
gdb_test "print * (A *) b" ".* = {a = 42}" \
"cast derived class pointer to base class pointer"
# Casting References.
# Check upcasting.
gdb_test "print (A &) br" ".* = .A &.* {a = 42}" \
"cast derived class reference to base class reference"
# Check downcasting.
gdb_test "print (B &) ar" ".* = .B.* {<A> = {a = 42}, b = 1729}" \
"cast base class reference to derived class reference"
# Check compiler casting
gdb_test "print br" ".* = .B.* {<A> = {a = 42}, b = 1729}" \
"let compiler cast base class reference to derived class reference"