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 c++/16675] New: invalid value of sizeof or reference in gdb


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

            Bug ID: 16675
           Summary: invalid value of sizeof or reference in gdb
           Product: gdb
           Version: 7.7
            Status: NEW
          Severity: normal
          Priority: P2
         Component: c++
          Assignee: unassigned at sourceware dot org
          Reporter: vladi_ian at yahoo dot com

problem with printing size of reference in gdb. The output is the size of
pointer, not the size of type.
In the next program
#include <iostream>
int main()
{
    typedef unsigned char a4[4];
    a4 p1;
    a4& p2 = p1;
    std::cout<<sizeof(p2);
    return 0;
}

Compile, start gdb and put breakpoint on return. If you type p sizeof(p2), gdb
will print 8 instead of 4 which will be printed if you start the program. If
you write in gdb p sizeof(*p2), the output is 4 (the size of array). I think
this is because gdb treats p2 as pointer(reference is implemented behind the
scene as pointer).

Tested with compilers GCC 4.8.2 and Clang 4.3 on GDB 7.7 linux arch., ubuntu
13.10,

There are also examples in
http://stackoverflow.com/questions/22255860/sizeof-reference-to-array-in-gdb?noredirect=1#comment33814516_22255860

-- 
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]