[backport from gcc-4.8/trunk r189225 ] gcc/cp/ 2012-07-03 Jakub Jelinek PR c++/53812 * semantics.c (finish_goto_stmt): Surround computed goto argument with CLEANUP_POINT_EXPR if needed. gcc/testsuite/ 2012-07-03 Jakub Jelinek PR c++/53812 * g++.dg/ext/label14.C: New test. --- gcc-4.6.3/gcc/cp/semantics.c.~1~ 2012-02-09 18:17:36.000000000 +0100 +++ gcc-4.6.3/gcc/cp/semantics.c 2012-08-11 17:47:42.000000000 +0200 @@ -568,6 +568,9 @@ finish_goto_stmt (tree destination) destination = cp_convert (ptr_type_node, destination); if (error_operand_p (destination)) return NULL_TREE; + destination + = fold_build_cleanup_point_expr (TREE_TYPE (destination), + destination); } /* We don't inline calls to functions with computed gotos. Those functions are typically up to some funny business, --- gcc-4.6.3/gcc/testsuite/g++.dg/ext/label14.C.~1~ 1970-01-01 01:00:00.000000000 +0100 +++ gcc-4.6.3/gcc/testsuite/g++.dg/ext/label14.C 2012-08-11 17:47:42.000000000 +0200 @@ -0,0 +1,17 @@ +// PR c++/53812 +// { dg-do compile } +// { dg-options "" } + +struct T { T () : t(0) {}; int t; ~T (); }; +struct S { void *operator [] (T); }; +void bar (S &, void *, void *); + +void +foo (S &x, T &y) +{ + bar (x, &&l1, &&l2); +l1: + goto *x[y]; +l2: + bar (x, &&l1, &&l2); +}