aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog7
-rw-r--r--gcc/cp/pt.c36
-rw-r--r--gcc/testsuite/g++.dg/template/stmtexpr1.C10
3 files changed, 35 insertions, 18 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 8e1f434..c8ba24d 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,10 @@
+2004-09-11 Richard Henderson <rth@redhat.com>
+
+ PR c++/17404
+ * pt.c (cur_stmt_expr): Move from tsubst_expr.
+ (tsubst_expr) <case STMT_EXPR>: Move ...
+ (tsubst_copy_and_build): ... here.
+
2004-09-10 Zack Weinberg <zack@codesourcery.com>
* cp-tree.h (interface_only, interface_unknown): Delete declarations;
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 3bdcf06..0a6b773 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 0000000..a470ca8
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/stmtexpr1.C
@@ -0,0 +1,10 @@
+// PR c++/17404
+// { dg-do compile }
+// { dg-options "" }
+
+template <int> void foo ()
+{
+ __builtin_expect (({0;}), 1);
+}
+
+template void foo<1> ();