This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/12298] New: Stack unwind destroys not-yet-constructed object


PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12298

           Summary: Stack unwind destroys not-yet-constructed object
           Product: gcc
           Version: 3.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: raoulgough at yahoo dot co dot uk
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i686-pc-mingw
  GCC host triplet: i686-pc-mingw
GCC target triplet: i686-pc-mingw

The following code asserts instead of completing normally. The constructor call 
to foo_base never happens, because of an exception during parameter set up. 
Unfortunately, the unwind code then calls the destructor on the never-
constructed object. i686-pc-cygwin g++ 3.2 produces code that completes 
normally, i686-pc-mingw g++ 3.3.1 gets the assertion failure.


#include <cassert>

static unsigned int const kMagic = 0x0f00ba4e;

struct foo_base {
  unsigned mConstructed;
  foo_base (void *) : mConstructed (kMagic) { }
  ~foo_base () { assert (mConstructed == kMagic); }
};

void *check_ptr (void *ptr) {
  if (!ptr) throw ptr;

  return ptr;
}

int main (int argc, char *argv[]) {
  try {
    foo_base const &ref ((foo_base (check_ptr (0))));
  }

  catch (void *) { }
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]