This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
C++ Evaluation Order
- To: gcc-bugs at gcc dot gnu dot org
- Subject: C++ Evaluation Order
- From: "Marc A. Lepage" <mlepage at molecularmining dot com>
- Date: Tue, 19 Dec 2000 15:26:52 -0500
- Organization: Molecular Mining Corporation
My GCC version:
mlepage@kafka:/tmp/bug$ gcc -v
Reading specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/specs
gcc version 2.95.2 19991024 (release)
This line of code crashes at runtime:
g_map[pFoo->getIdentifier()].reset(pFoo.release());
Important type details:
gmap is std::map<int, boost::shared_ptr<Foo> >
pFoo is std::auto_ptr<Foo>
Therefore, the above line of code gets the map item keyed with the
appropriate identifier (creating it if necessary), then resets its
shared pointer (deleting any existing Foo if its reference count reaches
zero) to the released auto_ptr (taking ownership of that Foo object).
My understanding is that pFoo->getIdentifier() should be called before
pFoo.release(). However, I am finding that pFoo.release() is being
called before pFoo->getIdentifier(), prematurely deleting the object, so
that the call to pFoo->getIdentifier() crashes with a SIGSEGV.
I've attached a .tar.gz file demonstrating the bug. Other than <map> and
<iostream>, the only included file is the boost smart pointer header,
which I've also provided.
I've included the output of the compile command:
g++ -v -save-temps -I. bug.cpp > compile-output.txt
--
Marc A. Lepage
Software Developer
Molecular Mining Corporation
http://www.molecularmining.com/
bug.tar.gz