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 exp/11863] New: Print return object inside function operates on wrong memory


Inside a function call that returns a class object, printing the object operates
on wrong data. See the example below which is compiled on Ubuntu 10.04 with
these versions:
g++ (Ubuntu 4.4.3-4ubuntu5) 4.4.3
GNU gdb (GDB) 7.1-ubuntu

with

g++ -Wall -g -pedantic test2.cpp -o test2

Rrunning gdb on the file results in the output below. gdb returns a different
address for the object that is returned than the print statement in the executed
code. For the other local object, both address agree. The same also holds when
accessing the object itself (not shown below).

-- %< -------------------------------------------------------------------
Breakpoint 1, testObj () at test2.cpp:21
21		std::cout << &obj << std::endl;
(gdb) p &obj
$1 = (testClass *) 0xbffff308
(gdb) p &obj2
$2 = (testClass *) 0xbffff300
(gdb) n
0xbffff338
22		std::cout << &obj2 << std::endl;
(gdb) n
0xbffff300
24	}
-- %< -------------------------------------------------------------------

-- %< ------------------------------------------------------------------- 
#include <iostream>

class testClass
{
        private:
        double t;
};

testClass testObj();

int main()
{
        testClass tmp = testObj();
        return 0;
}

testClass testObj()
{
        testClass obj, obj2;
        std::cout << &obj << std::endl;
        std::cout << &obj2 << std::endl;
        return obj;
}
-- %< -------------------------------------------------------------------

-- 
           Summary: Print return object inside function operates on wrong
                    memory
           Product: gdb
           Version: 7.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: exp
        AssignedTo: unassigned at sourceware dot org
        ReportedBy: awechsun at mit dot edu
                CC: gdb-prs at sourceware dot org
 GCC build triplet: i486-linux-gnu
  GCC host triplet: i486-linux-gnu
GCC target triplet: i486-linux-gnu


http://sourceware.org/bugzilla/show_bug.cgi?id=11863

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


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