From b69b1501dcb82cd3bef280398637ae1ac7f4254d Mon Sep 17 00:00:00 2001 From: Mark Mitchell Date: Tue, 28 Apr 1998 13:24:00 +0000 Subject: semantics.c (begin_stmt_expr): Avoid duplicating the effect of the expression in templates. * semantics.c (begin_stmt_expr): Avoid duplicating the effect of the expression in templates. (finish_stmt_expr): Likewise. From-SVN: r19469 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/semantics.c | 18 +++++++++++++++--- gcc/testsuite/g++.old-deja/g++.pt/stmtexpr2.C | 24 ++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.old-deja/g++.pt/stmtexpr2.C (limited to 'gcc') diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index b883155..c9c51bb 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +Tue Apr 28 13:22:01 1998 Mark Mitchell + + * semantics.c (begin_stmt_expr): Avoid duplicating the effect of + the expression in templates. + (finish_stmt_expr): Likewise. + 1998-04-28 Brendan Kehoe * decl2.c (ambiguous_decl): Fix NAME parm to be a tree, not int. diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index d43e611..e7b738a 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -761,14 +761,18 @@ finish_parenthesized_expr (expr) return expr; } -/* Begin a statement-expression. Returns a new RTL_EXPR if - appropriate. */ +/* Begin a statement-expression. The value returned must be passed to + finish_stmt_expr. */ tree begin_stmt_expr () { keep_next_level (); - return processing_template_decl ? NULL_TREE : expand_start_stmt_expr(); + /* If we're processing_template_decl, then the upcoming compound + statement will be chained onto the tree structure, starting at + last_tree. We return last_tree so that we can later unhook the + compound statement. */ + return processing_template_decl ? last_tree : expand_start_stmt_expr(); } /* Finish a statement-expression. RTL_EXPR should be the value @@ -807,6 +811,14 @@ finish_stmt_expr (rtl_expr, expr) } else result = expr; + + if (processing_template_decl) + { + /* Remove the compound statement from the tree structure; it is + now saved in the BIND_EXPR. */ + last_tree = rtl_expr; + TREE_CHAIN (last_tree) = NULL_TREE; + } return result; } diff --git a/gcc/testsuite/g++.old-deja/g++.pt/stmtexpr2.C b/gcc/testsuite/g++.old-deja/g++.pt/stmtexpr2.C new file mode 100644 index 0000000..475ad72 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.pt/stmtexpr2.C @@ -0,0 +1,24 @@ +extern "C" void abort(); + +int i; + +void g() +{ + i++; +} + +template +void f(T) +{ + __extension__ ({g();}); +} + +int main() +{ + f(3.0); + if (i != 1) + abort(); + + return 0; +} + -- cgit v1.1