Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 107477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:45:36+00:00 2026-05-11T01:45:36+00:00

The following code demonstrates a weird problem I have in a Turbo C++ Explorer

  • 0

The following code demonstrates a weird problem I have in a Turbo C++ Explorer project. One of the three stack objects in D::D() is not destroyed after going out of scope.

This only happens if compiled in release mode, the auto_ptrs a_ and b_ are of different types and the exception thrown doesn’t inherit from std::exception. It appears to work just fine in VC++ 2005 and C++ Builder 2009. I did install the BDS2006 Update 2, the hotfix rollup and hotfix 12.

Is it my code or the compiler? Do you know of a fix? Not being able to reliably use auto_ptr in a VCL project would be quite inconvenient.

#include <memory> #include <stdexcept> #include <iostream>  typedef std::exception my_error; // will work fine if replaced with line below //class my_error : public std::exception {};  class A {}; class B {};  class C { public:     C(int id) : id_(id) { std::cout << 'C::C() ' << id_ << std::endl; };     ~C() { std::cout << 'C::~C() ' << id_ << std::endl; }; private:     int id_; };  class D { public:     D()     {         C c1(1);         C c2(2);         C c3(3);          throw my_error();     };  private:     std::auto_ptr<A> a_;     std::auto_ptr<B> b_; // will work fine if replaced with line below //  std::auto_ptr<A> b_; //  std::auto_ptr<C> c_; // see expected output };  #pragma argsused int main(int argc, char* argv[]) {     try     {         D d;     }     catch (...)     {         std::cout << 'caught exception' << std::endl;     }      return 0; } 

Expected:

 C::C() 1 C::C() 2 C::C() 3 C::~C() 3 C::~C() 2 C::~C() 1 caught exception 

Got:

 C::C() 1 C::C() 2 C::C() 3 C::~C() 2 C::~C() 1 caught exception 

Got (with line ‘// std::auto_ptr<C> c_;‘ uncommented):

 C::C() 1 C::C() 2 C::C() 3 C::~C() 1 caught exception 

Edit: Made suggested changes

Edit 2:
I just tested it with C++ Builder 2007 (11.0.2902.10471), which shows the same problem. The release configuration works as soon as I check the ‘Debug information’ box in Project -> Options -> C++ Compiler -> Debugging. It surprises me that the executable gets smaller with ‘Debug information’ enabled (down to 31.5 KB from 39.5 KB ).

Edit 3:
In Turbo C++ Explorer (C++ Builder 2006) (10.0.2288.42451) the release configuration works if I uncheck the ‘Inline function expansion (-vi)’ box in Project -> Options -> C++ Compiler -> Debugging. Replacing the first line (#include <memory>) with the following code makes it work, too.

#pragma option push -vi- #include <memory> #pragma option pop  
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T01:45:37+00:00Added an answer on May 11, 2026 at 1:45 am

    This appears to be a compiler bug. I just ran the same sample in VS2008SP1 and got the expected output.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following code demonstrates my problem. Running it gives me the error message that
The following code demonstrates a problem with certain wx cursors on Windows (OSX cursors
The following code demonstrates a misleading situation in which data is committed to the
The following code demonstrates my dilemma. The code creates a background thread which processes
The following code works great in IE, but not in FF or Safari. I
I don't understand the code that comes after The following PHP example demonstrates the
The following code demonstrates a case where a checked exception, ExecutionException , is thrown
The following code demonstrates that the subclass named SubClass has a direct access to
Updated question to be more generic: I have the following code. When you swap
I have this fragment that demonstrates the problem: <html> <head> <title>height query demo</title> <script

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.