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]

C++ Evaluation Order


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


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