This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC 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++/34121] wrong this pointer passed to constructor of temporary object



------- Comment #2 from peter_foelsche at agilent dot com  2007-11-16 16:42 -------
the attached piece of source code does exhibit the compiler problem with the
new compiler.
When compiling using -O3 the code works fine. When compiling using -g the bug
happens.
Some temporary objects are being created and one constructor call for these
temporary objects gets the wrong address.
To exhibit this I put calls to printf() into the constructor and destructor
showing the this pointer.
Look at the end of the code to find the main function with one call to printf()
and several temporary objects of my old string class. (Btw I'm not using this
class anymore since we have std::string.)

Here comes the output of the test showing the problem.
You can see that the destructors are called in opposite order to the
destructors.

CString::CString(): this==0x7fbfff8d30
CString::CString(): this==0x7fbfff8c80
CString::CString(): this==0x7fbfff8dc0
CString::CString(): this==0x7fbfff8d60
CString::CString(): this==0x7fbfff8d00
testÉtest
CString::~CString(): this==0x7fbfff8d00
CString::~CString(): this==0x7fbfff8d60
CString::~CString(): this==0x7fbfff8dc0
CString::~CString(): this==0x7fbfff8d90
free(): invalid pointer 0x7fbfff8c88!
CString::~CString(): this==0x7fbfff8d30

If you dig deep into this code you will find that one object is of type derived
from CString.
This is where the compiler calculates the wrong address.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34121


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