Commit beb9c8a2 by Jason Merrill Committed by Jason Merrill

re PR c++/5757 (Throwing exception in constructor, causes segfault during unwind)

        PR c++/5757
        * init.c (build_new_1): Pass the right pointer to op delete.

From-SVN: r50917
parent 0ac7f923
2002-03-17 Jason Merrill <jason@redhat.com>
PR c++/5757
* init.c (build_new_1): Pass the right pointer to op delete.
2002-03-16 Nathan Sidwell <nathan@codesourcery.com> 2002-03-16 Nathan Sidwell <nathan@codesourcery.com>
PR c++/4361 PR c++/4361
......
...@@ -2288,7 +2288,7 @@ build_new_1 (exp) ...@@ -2288,7 +2288,7 @@ build_new_1 (exp)
use_cookie = 0; use_cookie = 0;
/* When using placement new, users may not realize that they need /* When using placement new, users may not realize that they need
the extra storage. We require that the operator called be the extra storage. We require that the operator called be
the global placement operator delete[]. */ the global placement operator new[]. */
else if (placement && !TREE_CHAIN (placement) else if (placement && !TREE_CHAIN (placement)
&& same_type_p (TREE_TYPE (TREE_VALUE (placement)), && same_type_p (TREE_TYPE (TREE_VALUE (placement)),
ptr_type_node)) ptr_type_node))
...@@ -2473,13 +2473,22 @@ build_new_1 (exp) ...@@ -2473,13 +2473,22 @@ build_new_1 (exp)
tree cleanup; tree cleanup;
int flags = (LOOKUP_NORMAL int flags = (LOOKUP_NORMAL
| (globally_qualified_p * LOOKUP_GLOBAL)); | (globally_qualified_p * LOOKUP_GLOBAL));
tree delete_node;
if (use_cookie)
/* Subtract the padding back out to get to the pointer returned
from operator new. */
delete_node = fold (build (MINUS_EXPR, TREE_TYPE (alloc_node),
alloc_node, cookie_size));
else
delete_node = alloc_node;
/* The Standard is unclear here, but the right thing to do /* The Standard is unclear here, but the right thing to do
is to use the same method for finding deallocation is to use the same method for finding deallocation
functions that we use for finding allocation functions. */ functions that we use for finding allocation functions. */
flags |= LOOKUP_SPECULATIVELY; flags |= LOOKUP_SPECULATIVELY;
cleanup = build_op_delete_call (dcode, alloc_node, size, flags, cleanup = build_op_delete_call (dcode, delete_node, size, flags,
(placement_allocation_fn_p (placement_allocation_fn_p
? alloc_call : NULL_TREE)); ? alloc_call : NULL_TREE));
......
// PR c++/5757
// Test that when a constructor throws in a new-expression, we pass the
// right pointer to operator delete.
// { dg-do run }
#include <new>
int ret = 1;
void *ptr;
void * operator new[] (size_t s) throw (std::bad_alloc)
{
ptr = operator new (s);
return ptr;
}
void operator delete[] (void *p) throw ()
{
if (p == ptr)
ret = 0;
operator delete (p);
}
struct A
{
A() { throw 1; }
~A() {}
};
int
main ()
{
try
{
A *p = new A[4];
}
catch (...) {}
return ret;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment