
Hi all, I've encountered a situation when destructors to local objects are not called after an exception is raised. I use Borland C++ version 5.6.4 (Borland C++Builder 6). The examples are compiled with following command to ensure that destructor cleanup is on: bcc32 -RT -x -xd -I<boost_include_path> boosttest.cpp bcc32 -RT -x -xd -I<boost_include_path> boosttest1.cpp The code is attached. Output of boosttest.cpp is: C:\buf\temp\ttt>boosttest1 A is created! Global shared_ptr<A> destroyed! A is created! Local A variable destroyed! A is created! auto_ptr<A> destroyed! A is created! scoped_ptr<A> destroyed! A is created! Local shared_ptr<A> destroyed! Access to global object through the local one! Global shared_ptr<A> destroyed! B is being created! scoped_ptr<A> destroyed! auto_ptr<A> destroyed! Local A variable destroyed! Exception cought: Too bad! Global shared_ptr<A> destroyed! Output of boosttest1.cpp is: C:\buf\temp\ttt>boosttest1 A is created! Global shared_ptr<A> destroyed! A is created! Local A variable destroyed! A is created! auto_ptr<A> destroyed! A is created! scoped_ptr<A> destroyed! A is created! Local shared_ptr<A> destroyed! Access to global object through the local one! Global shared_ptr<A> destroyed! B is being created! scoped_ptr<A> destroyed! auto_ptr<A> destroyed! Local A variable destroyed! Exception cought: Too bad! Global shared_ptr<A> destroyed! The problem is that the object created with the line "shared_ptr<A> spa(new A("Local shared_ptr<A> destroyed!"));" is destroyed in boosttest.cpp and is not destroyed in boosttest1.cpp. If shared_ptr is replaced with plain pointer, everything works fine (see boosttest2.cpp). I would appreciate explaining what's wrong in my code. TIA.

Serge Skorokhodov wrote:
Hi all,
I've encountered a situation when destructors to local objects are not called after an exception is raised. I use Borland C++ version 5.6.4 (Borland C++Builder 6). The examples are compiled with following command to ensure that destructor cleanup is on:
bcc32 -RT -x -xd -I<boost_include_path> boosttest.cpp bcc32 -RT -x -xd -I<boost_include_path> boosttest1.cpp
The code is attached. [...]
The problem is that the object created with the line
"shared_ptr<A> spa(new A("Local shared_ptr<A> destroyed!"));"
is destroyed in boosttest.cpp and is not destroyed in boosttest1.cpp. If shared_ptr is replaced with plain pointer, everything works fine (see boosttest2.cpp).
I would appreciate explaining what's wrong in my code.
Your code seems correct, and all non-Borland compilers agree. This looks like a particularly evil bcc32 bug.
participants (2)
-
Peter Dimov
-
Serge Skorokhodov