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

Ask A Question

Stats

  • Questions 150k
  • Answers 150k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Mark, I'm another contributor to JMVC. JMVC is designed to… May 12, 2026 at 9:46 am
  • Editorial Team
    Editorial Team added an answer It looks like the file /Users/Apu/Documents/GDB_Parent/scr/GDB/app/log/development.log cannot be created. Does… May 12, 2026 at 9:46 am
  • Editorial Team
    Editorial Team added an answer I think you've got the wrong idea about alternation (i.e.,… May 12, 2026 at 9:46 am

Related Questions

In a Flex DataGrid's first row, the itemRenderer will initialize twice. Tracing the results
When creating a UserControl in WPF, I find it convenient to give it some
I am looking for advice as to how to handle any exceptions thrown in
In JavaScript, I know that a closure is can be defined as a nested

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.