aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gdb/testsuite/gdb.cp/casts.cc2
-rw-r--r--gdb/testsuite/gdb.cp/casts.exp17
2 files changed, 19 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.cp/casts.cc b/gdb/testsuite/gdb.cp/casts.cc
index 831add9..6ecd340 100644
--- a/gdb/testsuite/gdb.cp/casts.cc
+++ b/gdb/testsuite/gdb.cp/casts.cc
@@ -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 */
}
diff --git a/gdb/testsuite/gdb.cp/casts.exp b/gdb/testsuite/gdb.cp/casts.exp
index 9d6c472..c8b7332 100644
--- a/gdb/testsuite/gdb.cp/casts.exp
+++ b/gdb/testsuite/gdb.cp/casts.exp
@@ -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"