http://llvm.org/bugs/show_bug.cgi?id=12286

             Bug #: 12286
           Summary: clang fails to destroy return value when a destructor
                    throws
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
        AssignedTo: [email protected]
        ReportedBy: [email protected]
                CC: [email protected], [email protected]
    Classification: Unclassified


If an exception is thrown after a non-POD return value is successfully
constructed in the return slot but before the returning function terminates,
the value in the return slot is not destroyed.  This can be clearly seen in the
following test case.  The really easy solution would be to push an inactive
destructor cleanup in the prologue and activate it whenever evaluation
completes for a return value, but that wouldn't be the correct ordering of
destruction as specified in [except.ctor]p1.  Needs more thought.

#include <stdio.h>

struct A {
  A() { printf("creating A at %p\n", this); }
  A(const A &a) { printf("copying A at %p into %p\n", &a, this); }
  ~A() { printf("destroying A at %p\n", this); }
};

struct B {
  B() { printf("entering B\n"); }
  ~B() { printf("exiting B, throwing!\n"); throw 0; }
};

A test() {
  B b;
  return A();
}

int main() {
  try {
    printf("running\n");
    A a = test();
  } catch (int i) {
    printf("caught\n");
  }
}

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to