public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug exp/11863] New: Print return object inside function operates on wrong memory
@ 2010-07-30 19:03 awechsun at mit dot edu
0 siblings, 0 replies; only message in thread
From: awechsun at mit dot edu @ 2010-07-30 19:03 UTC (permalink / raw)
To: gdb-prs
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.
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2010-07-30 19:03 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-07-30 19:03 [Bug exp/11863] New: Print return object inside function operates on wrong memory awechsun at mit dot edu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).