]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
Fix reinterpret_cast for classes with multiple inheritance
authorHannes Domani <ssbssa@yahoo.de>
Wed, 20 Mar 2024 17:02:06 +0000 (18:02 +0100)
committerHannes Domani <ssbssa@yahoo.de>
Wed, 20 Mar 2024 17:02:06 +0000 (18:02 +0100)
commit23cdd9431ad424b092c65419d47ef4601168a1c9
treeafb675baa8627d111c515e4b733f4f915fd7d7f0
parente8f6050cfb990452fcfc685bc9ccbae79113fa36
Fix reinterpret_cast for classes with multiple inheritance

Currently a reinterpret_cast may change the pointer value if
multiple inheritance is involved:
```
(gdb) p r
$1 = (Right *) 0x22f75c
(gdb) p reinterpret_cast<LeftRight*>(r)
$2 = (LeftRight *) 0x22f758
```

It's because value_cast is called in this case, which automatically
does up- and downcasting.

Fixed by simply using the target pointer type in a copy of the
original value:
```
(gdb) p r
$1 = (Right *) 0x3bf87c
(gdb) p reinterpret_cast<LeftRight*>(r)
$2 = (LeftRight *) 0x3bf87c
```

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=18861
Approved-By: Tom Tromey <tom@tromey.com>
gdb/testsuite/gdb.cp/casts.cc
gdb/testsuite/gdb.cp/casts.exp
gdb/valops.c