This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Lifetime of temporaries in new expressions
- To: egcs-patches at cygnus dot com
- Subject: Lifetime of temporaries in new expressions
- From: Martin von Loewis <martin at mira dot isdn dot cs dot tu-berlin dot de>
- Date: Tue, 20 Oct 1998 07:30:45 +0100
g++ incorrectly inserts a CLEANUP_POINT_EXPR inside each `new'
invocation. As a result, destructors are called too early, as
shown in g++.martin/new1.C.
The correct code is already in init.c. Enabling it, I could not detect
any regression failure in the testsuite. There is some mentioning of
flow problems, but these appear to be fixed.
I propose to activate this code. If somebody can confirm that the
original problem is fixed, I also propose to activate it in the
release branch.
1998-10-20 Martin v. Löwis <loewis@informatik.hu-berlin.de>
* init.c (build_new_1): Delay cleanup until end of full expression.
Index: init.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/init.c,v
retrieving revision 1.69
diff -c -3 -p -r1.69 init.c
*** init.c 1998/10/16 03:37:40 1.69
--- init.c 1998/10/20 06:20:49
*************** build_new_1 (exp)
*** 2472,2480 ****
if (cleanup)
{
- #if 0
- /* Disable this until flow is fixed so that it doesn't
- think the initialization of sentry is a dead write. */
tree end, sentry, begin, buf, t = TREE_TYPE (rval);
begin = get_target_expr (boolean_true_node);
--- 2472,2477 ----
*************** build_new_1 (exp)
*** 2497,2510 ****
rval = build (COMPOUND_EXPR, t, begin,
build (COMPOUND_EXPR, t, rval,
build (COMPOUND_EXPR, t, end, buf)));
- #else
- /* FIXME: this is a workaround for a crash due to overlapping
- exception regions. Cleanups shouldn't really happen here. */
- rval = build1 (CLEANUP_POINT_EXPR, TREE_TYPE (rval), rval);
-
- rval = build (TRY_CATCH_EXPR, TREE_TYPE (rval), rval, cleanup);
- rval = build (COMPOUND_EXPR, TREE_TYPE (rval), alloc_expr, rval);
- #endif
}
}
}
--- 2494,2499 ----