c++/411: destructors of member objects not called when an exception is thrown in the destructor of the containing object.

llewelly@dbritsch.dsl.xmission.com llewelly@dbritsch.dsl.xmission.com
Thu Jul 13 16:26:00 GMT 2000


>Number:         411
>Category:       c++
>Synopsis:       destructors of member objects not called when an exception is thrown in the destructor of the containing object.
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Jul 13 16:26:00 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator:     llewelly@dbritsch.dsl.xmission.com
>Release:        gcc version 2.96 20000626, gcc 2.95.2
>Organization:
>Environment:
i686-pc-linux-gnu, glibc-2.1.2
>Description:
/*
  15.2/2 says:
  # An object that is partially constructed or partially destroyed
  # will have destructors executed for all of its partially
  # constructed subobjects, that is, for subobjects which the
  # constructor has completed execution and the destructor has not
  # begun execution. [... ]

  So the 'throw 1' expression in Bar::~Bar() should cause Bar::f's
    destructor to be called, causing this program should return 0.

  However, when compiled with gcc version 2.96 20000626
    (experimental), or with gcc 2.95.2, the destructor for Bar::f is
    never called, so it returns 1.
 */


bool was_f_in_Bar_destroyed=false;

struct Foo
{
  ~Foo()
  {
    was_f_in_Bar_destroyed=true;
  }
};

struct Bar
{
  ~Bar()
  {
    throw 1;
  }

  Foo f;
};

int main()
  {
    try
    {
      Bar f;  
    }
    catch(int i)
    {
      if(was_f_in_Bar_destroyed)
      {
        return 0;
      }
    }
    return 1;
  }
>How-To-Repeat:

>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the Gcc-prs mailing list