diff options
author | Mark Mitchell <mmitchell@usa.net> | 1998-04-28 13:24:00 +0000 |
---|---|---|
committer | Mark Mitchell <mmitchel@gcc.gnu.org> | 1998-04-28 13:24:00 +0000 |
commit | b69b1501dcb82cd3bef280398637ae1ac7f4254d (patch) | |
tree | a1d223f3c63c9e5142c933628fda85f989cfb3d9 | |
parent | 69fa83cfbbbbf834f54d8b0926ea1f355ea0ee46 (diff) | |
download | gcc-b69b1501dcb82cd3bef280398637ae1ac7f4254d.zip gcc-b69b1501dcb82cd3bef280398637ae1ac7f4254d.tar.gz gcc-b69b1501dcb82cd3bef280398637ae1ac7f4254d.tar.bz2 |
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
-rw-r--r-- | gcc/cp/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/cp/semantics.c | 18 | ||||
-rw-r--r-- | gcc/testsuite/g++.old-deja/g++.pt/stmtexpr2.C | 24 |
3 files changed, 45 insertions, 3 deletions
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 <mmitchell@usa.net> + + * semantics.c (begin_stmt_expr): Avoid duplicating the effect of + the expression in templates. + (finish_stmt_expr): Likewise. + 1998-04-28 Brendan Kehoe <brendan@cygnus.com> * 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 <class T> +void f(T) +{ + __extension__ ({g();}); +} + +int main() +{ + f(3.0); + if (i != 1) + abort(); + + return 0; +} + |