From f0050c208902d6609eb02162b33d8e64003fbce5 Mon Sep 17 00:00:00 2001 From: Aleksandar Ristovski Date: Tue, 1 Apr 2008 16:16:43 +0000 Subject: [PATCH] * gdb.cp/casts.cc: Add class reference variables. * gdb.cp/casts.exp: New test cases for up/down casting references. --- gdb/testsuite/gdb.cp/casts.cc | 2 ++ gdb/testsuite/gdb.cp/casts.exp | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/gdb/testsuite/gdb.cp/casts.cc b/gdb/testsuite/gdb.cp/casts.cc index 831add94418..6ecd340c21e 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 9d6c472a7e2..c8b7332f9ad 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 = 42}, b = 1729}" \ # the dereference. gdb_test "print * b" ".* = { = {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 = 42}, b = 1729}" \ + "cast base class reference to derived class reference" + +# Check compiler casting +gdb_test "print br" ".* = .B.* { = {a = 42}, b = 1729}" \ + "let compiler cast base class reference to derived class reference" -- 2.30.2