diff options
author | Tom Tromey <tromey@redhat.com> | 2010-01-18 20:54:35 +0000 |
---|---|---|
committer | Tom Tromey <tromey@redhat.com> | 2010-01-18 20:54:35 +0000 |
commit | 4e8f195d9dd0be6a5caf9349883db5a531aabd5f (patch) | |
tree | 4135b82af0d720a7a7e9786de58cf7cfc9486885 /gdb/testsuite/gdb.cp/casts.exp | |
parent | d9c57d9ff1bf3533ddb272717afe2b18f61dd017 (diff) | |
download | gdb-4e8f195d9dd0be6a5caf9349883db5a531aabd5f.zip gdb-4e8f195d9dd0be6a5caf9349883db5a531aabd5f.tar.gz gdb-4e8f195d9dd0be6a5caf9349883db5a531aabd5f.tar.bz2 |
gdb
PR c++/9680:
* c-exp.y (REINTERPRET_CAST, DYNAMIC_CAST, STATIC_CAST)
(CONST_CAST): New tokens.
(exp): Add new productions.
(ident_tokens): Add const_cast, dynamic_cast, static_cast, and
reinterpret_cast.
(is_cast_operator): New function.
(yylex): Handle cast operators specially.
* eval.c (evaluate_subexp_standard) <UNOP_DYNAMIC_CAST,
UNOP_REINTERPRET_CAST>: New cases.
* expprint.c (print_subexp_standard): Likewise.
(op_name_standard): Likewise.
(dump_subexp_body_standard): Likewise.
* parse.c (operator_length_standard): Likewise.
* expression.h (enum exp_opcode): New constants UNOP_DYNAMIC_CAST,
UNOP_REINTERPRET_CAST.
* gdbtypes.c (class_types_same_p): New function.
(is_ancestor): Use it.
(is_public_ancestor): New function.
(is_unique_ancestor_worker): Likewise.
(is_unique_ancestor): Likewise.
* gdbtypes.h (class_types_same_p, is_public_ancestor)
(is_unique_ancestor): Declare.
* valops.c (value_reinterpret_cast): New function.
(dynamic_cast_check_1): Likewise.
(dynamic_cast_check_2): Likewise.
(value_dynamic_cast): Likewise.
* value.h (value_reinterpret_cast, value_dynamic_cast): Declare.
gdb/testsuite
PR c++/9680:
* gdb.cp/casts.cc: Add new classes and variables.
* gdb.cp/casts.exp: Test new operators.
Diffstat (limited to 'gdb/testsuite/gdb.cp/casts.exp')
-rw-r--r-- | gdb/testsuite/gdb.cp/casts.exp | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.cp/casts.exp b/gdb/testsuite/gdb.cp/casts.exp index c87d604..926f81b 100644 --- a/gdb/testsuite/gdb.cp/casts.exp +++ b/gdb/testsuite/gdb.cp/casts.exp @@ -98,3 +98,75 @@ gdb_test "print (B &) ar" ".* = .B.* {<A> = {a = 42}, b = 1729}" \ # Check compiler casting gdb_test "print br" ".* = .B.* {<A> = {a = 42}, b = 1729}" \ "let compiler cast base class reference to derived class reference" + + +# A few basic tests of "new" casts. + +gdb_test "print const_cast<const B *> (b)" " = \\(const B \\*\\) $hex" \ + "basic test of const_cast" + +gdb_test "print const_cast<void *> (0)" " = \\(void \\*\\) 0x0" \ + "const_cast of 0" + +gdb_test "print static_cast<A *> (b)" " = \\(A \\*\\) $hex" \ + "basic test of static_cast" + +gdb_test "print static_cast<A &> (*b)" " = \\(A \\&\\) @$hex: {a = 42}" \ + "static_cast to reference type" + +gdb_test "print reinterpret_cast<A *> (b)" " = \\(A \\*\\) $hex" \ + "basic test of reinterpret_cast" + +gdb_test "print reinterpret_cast<void> (b)" "Invalid reinterpret_cast" \ + "test invalid reinterpret_cast" + +gdb_test "print reinterpret_cast<A &> (*b)" " = \\(A \\&\\) @$hex: {a = 42}" \ + "reinterpret_cast to reference type" + +# Tests of dynamic_cast. + +set nonzero_hex "0x\[0-9A-Fa-f\]\[0-9A-Fa-f\]+" + +gdb_test "print dynamic_cast<void> (a)" \ + ".*must be a pointer or reference type" \ + "invalid dynamic_cast" + +gdb_test "print dynamic_cast<void *> (0)" \ + " = \\(void \\*\\) 0x0" \ + "dynamic_cast of 0 to void*" + +gdb_test "print dynamic_cast<Alpha *> (&derived)" \ + " = \\(Alpha \\*\\) $nonzero_hex" \ + "dynamic_cast simple upcast" + +gdb_test "print dynamic_cast<Alpha *> (&doublyderived)" \ + " = \\(Alpha \\*\\) $nonzero_hex" \ + "dynamic_cast upcast to unique base" + +gdb_test "print dynamic_cast<Alpha &> (derived)" \ + " = \\(Alpha \\&\\) @$nonzero_hex: {.* = $nonzero_hex}" \ + "dynamic_cast simple upcast to reference" + +gdb_test "print dynamic_cast<Derived *> (ad)" \ + " = \\(Derived \\*\\) $nonzero_hex" \ + "dynamic_cast simple downcast" + +gdb_test "print dynamic_cast<VirtuallyDerived *> (add)" \ + " = \\(VirtuallyDerived \\*\\) $nonzero_hex" \ + "dynamic_cast simple downcast to intermediate class" + +gdb_test "print dynamic_cast<VirtuallyDerived *> (ad)" \ + " = \\(VirtuallyDerived \\*\\) 0x0" \ + "dynamic_cast to non-existing base" + +gdb_test "print dynamic_cast<VirtuallyDerived &> (*ad)" \ + "dynamic_cast failed" \ + "dynamic_cast to reference to non-existing base" + +gdb_test "print dynamic_cast<DoublyDerived *> (add)" \ + " = \\(DoublyDerived \\*\\) $nonzero_hex" \ + "dynamic_cast unique downcast" + +gdb_test "print dynamic_cast<Gamma *> (add)" \ + " = \\(Gamma \\*\\) $nonzero_hex" \ + "dynamic_cast to sibling" |