From: Jason Merrill Date: Wed, 3 Mar 2004 07:40:31 +0000 (-0500) Subject: re PR c++/13944 (exception in constructor of a class to be thrown is not caught) X-Git-Tag: releases/gcc-3.3.4~204 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ef55cd500bf22ed50265661ac09c3a8e3939d7b9;p=thirdparty%2Fgcc.git re PR c++/13944 (exception in constructor of a class to be thrown is not caught) PR c++/13944 * except.c (do_free_exception): Remove #if 0 wrapper. (build_throw): Use it if we elide a copy into the exception object. From-SVN: r78823 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 0ee0b2182f27..cfd1a6ba4294 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2004-02-24 Jason Merrill + + PR c++/13944 + * except.c (do_free_exception): Remove #if 0 wrapper. + (build_throw): Use it if we elide a copy into the exception object. + 2004-03-01 Gabriel Dos Reis * decl.c (current_binding_level): Define as an lvalue. diff --git a/gcc/cp/except.c b/gcc/cp/except.c index 747cc1aaef69..6b32a5bd08dd 100644 --- a/gcc/cp/except.c +++ b/gcc/cp/except.c @@ -511,9 +511,7 @@ do_allocate_exception (type) NULL_TREE)); } -#if 0 -/* Call __cxa_free_exception from a cleanup. This is never invoked - directly, but see the comment for stabilize_throw_expr. */ +/* Call __cxa_free_exception from a cleanup. */ static tree do_free_exception (ptr) @@ -533,7 +531,6 @@ do_free_exception (ptr) return build_function_call (fn, tree_cons (NULL_TREE, ptr, NULL_TREE)); } -#endif /* Wrap all cleanups for TARGET_EXPRs in MUST_NOT_THROW_EXPR. Called from build_throw via walk_tree_without_duplicates. */ @@ -669,6 +666,7 @@ build_throw (exp) tree object, ptr; tree tmp; tree temp_expr, allocate_expr; + bool elided; fn = get_identifier ("__cxa_throw"); if (IDENTIFIER_GLOBAL_VALUE (fn)) @@ -723,6 +721,8 @@ build_throw (exp) object = build1 (NOP_EXPR, build_pointer_type (TREE_TYPE (exp)), ptr); object = build_indirect_ref (object, NULL); + elided = (TREE_CODE (exp) == TARGET_EXPR); + /* And initialize the exception object. */ exp = build_init (object, exp, LOOKUP_ONLYCONVERTING); if (exp == error_mark_node) @@ -731,7 +731,11 @@ build_throw (exp) return error_mark_node; } - exp = build1 (MUST_NOT_THROW_EXPR, TREE_TYPE (exp), exp); + if (elided) + exp = build (TRY_CATCH_EXPR, void_type_node, exp, + do_free_exception (ptr)); + else + exp = build1 (MUST_NOT_THROW_EXPR, void_type_node, exp); /* Prepend the allocation. */ exp = build (COMPOUND_EXPR, TREE_TYPE (exp), allocate_expr, exp); if (temp_expr != void_zero_node)