This is the mail archive of the gdb-prs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug gdb/18861] New: 'reinterpret_cast' in gdb seems to be doing a 'static_cast'.


https://sourceware.org/bugzilla/show_bug.cgi?id=18861

            Bug ID: 18861
           Summary: 'reinterpret_cast' in gdb seems to be doing a
                    'static_cast'.
           Product: gdb
           Version: unknown
            Status: NEW
          Severity: normal
          Priority: P2
         Component: gdb
          Assignee: unassigned at sourceware dot org
          Reporter: cs120hcc at yahoo dot com
  Target Milestone: ---

Created attachment 8544
  --> https://sourceware.org/bugzilla/attachment.cgi?id=8544&action=edit
Sample Code and Repro Transcript

Problem: 'reinterpret_cast' in gdb seems to be doing a 'static_cast'.

For example, assume we have two unrelated base classes, 'fred' and 'ginger',
and another class 'hillary' that first extends 'fred' then 'ginger'. 
Typically, a 'hillary' object would have the same address as the inherited
'fred' object.  The inherited 'ginger' object typically follows the 'fred'
data.  (It depends on the compiler implementation, but don't let that distract
you from the description of the gdb bug.)

'reinterpret_cast' typically does not change the value of a pointer that is
casts.  Specifically, given 'ginger*' pointer 'g',
'reinterpret_cast<hillary*>(g)' should have the same value as
'static_cast<hillary*>(static_cast<void*>(g))' per 5.2.10.7 of the 2011 and
2014 versions of the C++ standard (N3242 and N4296).  Notice that it does work
properly in code generated by g++.  However, in the various versions of gdb, it
does not.

The bug is reproduced is several GDB versions and distributions.
> GNU gdb (GDB) 7.4.1-debian          installed using apt-get
> GNU gdb (GDB) 7.9.1                 downloaded from gnu.org/software/gdb/download/
> GNU gdb (GDB) 7.10.50.20150818-cvs  downloaded from gnu.org/software/gdb/download/
> GNU gdb (Gentoo 7.5.1 p2) 7.5.1     installed using portage

Attached is sample code with several transcripts showing the problem.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]