I'm new here; I searched the Yahoo archive and didn't see anything about this so I apologize if this has been discussed before. Today I learned (the hard and painful way) that there is a bug in Borland C++ Builder 5.5 such that when compiling with debug support, the compiler thinks it needs to generate destructors in the wrong translation units. We noticed this because we were using the "handle-body" idiom with auto_ptr's (taking all the precautions from Herb Sutter's Exceptional C++ books) and our destructors were not getting called. We switched over to boost::shared_ptr's and the handy-dandy compile time check in the destructor for incomplete types was firing...but in the code that uses and declares objects of the classes that have the handle-body idiom...a pretty serious bug in my view. We then tried to compile the example code from boost for scoped_ptr and it would not compile for the same reason. A quick search of the newsgroups reveals that others have found this bug, and C++ Builder is the only major compiler that has this flaw. I've heard that it has been fixed in version 6. Can others verify this? So I am posting this for 2 reasons: 1) to let others know about it (in case you don't know already), and 2) I noticed that in the Boost compiler status web-page it says that smart_ptr passed all its tests with C++ Builder 5.5.1. I didn't look at the tests, but was this handle-body type usage tested to make sure the destructor was called? Or perhaps it was but without debug support turned on? Thanks, Brian Neal
This was discussed during Boost.Test review. Peter some time ago made a changes in boost::shared_ptr that allows it to be used with Borland 5.5 namely in the situation you described. Gennadiy.
--- In Boost-Users@y..., "Gennadiy E. Rozental"
This was discussed during Boost.Test review. Peter some time ago made a changes in boost::shared_ptr that allows it to be used with Borland 5.5 namely in the situation you described.
Gennadiy.
Hi...could you clarify this? All I noticed was that shared_ptr had that compile time check for an incomplete type removed, whereas scoped_ptr still has it. Are you saying that if I switch from scoped_ptr to shared_ptr the destructor will get called? Regards, Brian Neal
--- In Boost-Users@y..., "Brian"
--- In Boost-Users@y..., "Gennadiy E. Rozental"
wrote: This was discussed during Boost.Test review. Peter some time ago made a changes in boost::shared_ptr that allows it to be used with Borland 5.5 namely in the situation you described.
Gennadiy.
Hi...could you clarify this? All I noticed was that shared_ptr had that compile time check for an incomplete type removed, whereas scoped_ptr still has it. Are you saying that if I switch from scoped_ptr to shared_ptr the destructor will get called?
Regards,
Brian Neal
The general idea: class A { ... A() : m_deleter( checked_deleter() ) ~A() { m_deleter( m_ptr ); } deleter_function m_deleter; T* m_ptr; }; AFAIK this way compiler does not know in a destructor what will happend with the m_ptr and does not try to istantiate ~T(). Gennadiiy.
From: "Brian"
--- In Boost-Users@y..., "Gennadiy E. Rozental"
wrote: This was discussed during Boost.Test review. Peter some time ago made a changes in boost::shared_ptr that allows it to be used with Borland 5.5 namely in the situation you described.
Gennadiy.
Hi...could you clarify this? All I noticed was that shared_ptr had that compile time check for an incomplete type removed, whereas scoped_ptr still has it. Are you saying that if I switch from scoped_ptr to shared_ptr the destructor will get called?
Yes, shared_ptr will call the destructor. It only requires a complete type at construction time.
--- In Boost-Users@y..., "Peter Dimov"
Yes, shared_ptr will call the destructor. It only requires a complete type at construction time.
Hmmm... we tried using shared_ptr today and our destructors were still not called. This is with C++ Builder 5.5. I am now trying to see if another department has a copy of 6.0 we could try. Thanks, BN
From: "Brian"
--- In Boost-Users@y..., "Peter Dimov"
wrote: ... Yes, shared_ptr will call the destructor. It only requires a complete type at construction time.
Hmmm... we tried using shared_ptr today and our destructors were still not called. This is with C++ Builder 5.5. I am now trying to see if another department has a copy of 6.0 we could try.
What version of boost? Can you post a minimal example? It works here:
testbed.cpp:
#include
Peter, the Borland 5.5.1 compiler behaves differently according to whether you enable the generation of debugging information or not. To further confuse the issue, the command line compiler has debug information generation turned off by default, while BCB5 has it on. The problem with shared_ptr only happens with debugging information turned on. The 1.28.0 version of shared_ptr is handled correctly by the 5.6.1 compiler (the one in BCB6 with Update 2 installed). Cheers, Nicola Musatti
From: "Nicola Musatti"
Peter, the Borland 5.5.1 compiler behaves differently according to whether you enable the generation of debugging information or not. To further confuse the issue, the command line compiler has debug information generation turned off by default, while BCB5 has it on.
The problem with shared_ptr only happens with debugging information turned on. The 1.28.0 version of shared_ptr is handled correctly by the 5.6.1 compiler (the one in BCB6 with Update 2 installed).
Once again, can someone please post an example that demonstrates the problem? I did use the -v switch with my example, and it worked.
--- In Boost-Users@y..., "Peter Dimov"
From: "Nicola Musatti"
Peter, the Borland 5.5.1 compiler behaves differently according to whether you enable the generation of debugging information or not. To further confuse the issue, the command line compiler has debug information generation turned off by default, while BCB5 has it on.
The problem with shared_ptr only happens with debugging information turned on. The 1.28.0 version of shared_ptr is handled correctly by the 5.6.1 compiler (the one in BCB6 with Update 2 installed).
Once again, can someone please post an example that demonstrates the problem? I did use the -v switch with my example, and it worked.
Here is a summary of my experiences. I used the following: 1) boost 1.27.0 2) Borland C++ Builder command line compiler bcc32 version 5.5 3) Debug was turned on With these 3, I was able to successfully implement a handle-body idiom type class. I.e. the destructor for my private body implementation WAS called when the handle class was destroyed. If instead I use auto_ptr, the destructor is NOT called. If instead I use scoped_ptr, it will not compile due to a bug in Borland. Earlier, I reported that shared_ptr didn't work but I can't reproduce that now. Sorry for the confusion. BN
Peter Dimov wrote:
From: "Nicola Musatti"
[...]
The problem with shared_ptr only happens with debugging information turned on. The 1.28.0 version of shared_ptr is handled correctly by the 5.6.1 compiler (the one in BCB6 with Update 2 installed).
Once again, can someone please post an example that demonstrates the problem? I did use the -v switch with my example, and it worked.
I was too hasty. shared_ptr from 1.28.0 appears to work with Borland's 5.5.1 compiler regardless of debug switch setting. Cheers, Nicola Musatti
--- In Boost-Users@y..., "Peter Dimov"
From: "Brian"
... Hmmm... we tried using shared_ptr today and our destructors were still not called. This is with C++ Builder 5.5. I am now trying to see if another department has a copy of 6.0 we could try.
What version of boost? Can you post a minimal example? It works here: <example elided>
Peter, thanks for posting this. Your example does indeed work in our environment (Boost 1.27.0 and C++ Builder 5.5). I am at a loss why our code did not. If I find anything out I'll report back here. Thanks again, Brian Neal
Hi...could you clarify this? All I noticed was that shared_ptr had that compile time check for an incomplete type removed, whereas scoped_ptr still has it. Are you saying that if I switch from scoped_ptr to shared_ptr the destructor will get called?
The problem still persists with C++ Builder 6 and scoped_ptr, shared_ptr is OK though. John Maddock http://ourworld.compuserve.com/homepages/john_maddock/index.htm
participants (6)
-
Brian
-
Brian Neal
-
Gennadiy E. Rozental
-
John Maddock
-
Nicola Musatti
-
Peter Dimov