From 0fe0caa6d942920ebaab6197c8bedb4e371e9110 Mon Sep 17 00:00:00 2001 From: Richard Henderson Date: Sat, 11 Sep 2004 21:45:59 -0700 Subject: [PATCH] pt.c (cur_stmt_expr): Move from tsubst_expr. * pt.c (cur_stmt_expr): Move from tsubst_expr. (tsubst_expr) : Move ... (tsubst_copy_and_build): ... here. From-SVN: r87385 --- gcc/cp/ChangeLog | 7 +++++ gcc/cp/pt.c | 36 +++++++++++------------ gcc/testsuite/g++.dg/template/stmtexpr1.C | 10 +++++++ 3 files changed, 35 insertions(+), 18 deletions(-) create mode 100644 gcc/testsuite/g++.dg/template/stmtexpr1.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 8e1f434f175..c8ba24d4960 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2004-09-11 Richard Henderson + + PR c++/17404 + * pt.c (cur_stmt_expr): Move from tsubst_expr. + (tsubst_expr) : Move ... + (tsubst_copy_and_build): ... here. + 2004-09-10 Zack Weinberg * cp-tree.h (interface_only, interface_unknown): Delete declarations; diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 3bdcf06830c..0a6b773d1ad 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -67,6 +67,11 @@ static GTY(()) tree current_tinst_level; static GTY(()) tree saved_access_scope; +/* Live only within one (recursive) call to tsubst_expr. We use + this to pass the statement expression node from the STMT_EXPR + to the EXPR_STMT that is its result. */ +static tree cur_stmt_expr; + /* A map from local variable declarations in the body of the template presently being instantiated to the corresponding instantiated local variables. */ @@ -7790,11 +7795,6 @@ tsubst_copy (tree t, tree args, tsubst_flags_t complain, tree in_decl) static tree tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl) { - /* Live only within one (recursive) call to tsubst_expr. We use - this to pass the statement expression node from the STMT_EXPR - to the EXPR_STMT that is its result. */ - static tree cur_stmt_expr; - tree stmt, tmp; if (t == NULL_TREE || t == error_mark_node) @@ -7825,19 +7825,6 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl) args, complain, in_decl)); break; - case STMT_EXPR: - { - tree old_stmt_expr = cur_stmt_expr; - tree stmt_expr = begin_stmt_expr (); - - cur_stmt_expr = stmt_expr; - tsubst_expr (STMT_EXPR_STMT (t), args, complain, in_decl); - stmt_expr = finish_stmt_expr (stmt_expr, false); - cur_stmt_expr = old_stmt_expr; - - return stmt_expr; - } - case EXPR_STMT: tmp = tsubst_expr (EXPR_STMT_EXPR (t), args, complain, in_decl); if (EXPR_STMT_STMT_EXPR_RESULT (t)) @@ -8626,6 +8613,19 @@ tsubst_copy_and_build (tree t, case OFFSETOF_EXPR: return fold_offsetof (RECUR (TREE_OPERAND (t, 0))); + case STMT_EXPR: + { + tree old_stmt_expr = cur_stmt_expr; + tree stmt_expr = begin_stmt_expr (); + + cur_stmt_expr = stmt_expr; + tsubst_expr (STMT_EXPR_STMT (t), args, complain, in_decl); + stmt_expr = finish_stmt_expr (stmt_expr, false); + cur_stmt_expr = old_stmt_expr; + + return stmt_expr; + } + default: return tsubst_copy (t, args, complain, in_decl); } diff --git a/gcc/testsuite/g++.dg/template/stmtexpr1.C b/gcc/testsuite/g++.dg/template/stmtexpr1.C new file mode 100644 index 00000000000..a470ca8f14f --- /dev/null +++ b/gcc/testsuite/g++.dg/template/stmtexpr1.C @@ -0,0 +1,10 @@ +// PR c++/17404 +// { dg-do compile } +// { dg-options "" } + +template void foo () +{ + __builtin_expect (({0;}), 1); +} + +template void foo<1> (); -- 2.30.2