diff options
author | Tom Tromey <tom@tromey.com> | 2022-04-02 09:54:40 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2022-04-18 09:34:55 -0600 |
commit | 2390419d1cb72882110538e01e5586372df19657 (patch) | |
tree | 184695bb4127c296ef8c1305e48fca1c0e27fdfb /gdb/testsuite/gdb.cp/casts.exp | |
parent | c67f4e53895da91ce7f2eff3544e9de02280f740 (diff) | |
download | gdb-2390419d1cb72882110538e01e5586372df19657.zip gdb-2390419d1cb72882110538e01e5586372df19657.tar.gz gdb-2390419d1cb72882110538e01e5586372df19657.tar.bz2 |
Fix C++ cast of derived class to base class
PR c++/28907 points out that casting from a derived class to a base
class fails in some situations. The problem turned out to be a
missing use of value_embedded_offset. One peculiarity here is that,
if you managed to construct a pointer-to-derived with an embedded
offset of 0, the cast would work -- for example, one of the two new
tests here passes without the patch.
This embedded offset stuff is an endless source of bugs. I wonder if
it's possible to get rid of it somehow.
Regression tested on x86-64 Fedora 34.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28907
Diffstat (limited to 'gdb/testsuite/gdb.cp/casts.exp')
-rw-r--r-- | gdb/testsuite/gdb.cp/casts.exp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.cp/casts.exp b/gdb/testsuite/gdb.cp/casts.exp index cda870f..5d0a524 100644 --- a/gdb/testsuite/gdb.cp/casts.exp +++ b/gdb/testsuite/gdb.cp/casts.exp @@ -174,6 +174,12 @@ gdb_test "print dynamic_cast<Gamma *> (add)" \ " = \\(Gamma \\*\\) $nonzero_hex" \ "dynamic_cast to sibling" +gdb_test "print (unsigned long long) &gd == gd_value" " = true" +gdb_test "print (unsigned long long) (LeftRight *) (Right *) &gd == gd_value" \ + " = true" +gdb_test "print (unsigned long long) (LeftRight *) (Right *) r_value == gd_value" \ + " = true" + if {[prepare_for_testing "failed to prepare" ${testfile}03 $srcfile2 \ {debug c++ additional_flags=-std=c++03}]} { return -1 |