Commit 67da3287 by Mark Mitchell Committed by Jason Merrill

parse.y (primary): Deal with statement-expressions in templates.

	* parse.y (primary): Deal with statement-expressions in
	templates.
	* pt.c (tsubst_copy): Handle BIND_EXPR.
	* tree.c (mapcar): Likewise.

From-SVN: r17611
parent 0340ed6c
Mon Feb 2 11:24:22 1998 Mark Mitchell <mmitchell@usa.net> Mon Feb 2 11:24:22 1998 Mark Mitchell <mmitchell@usa.net>
* parse.y (primary): Deal with statement-expressions in
templates.
* pt.c (tsubst_copy): Handle BIND_EXPR.
* tree.c (mapcar): Likewise.
* call.c (add_template_candidate_real): Pass extra parameter to * call.c (add_template_candidate_real): Pass extra parameter to
fn_type_unification. fn_type_unification.
* cp-tree.h (fn_type_unification): Add parameter. * cp-tree.h (fn_type_unification): Add parameter.
......
...@@ -1434,20 +1434,33 @@ primary: ...@@ -1434,20 +1434,33 @@ primary:
YYERROR; YYERROR;
} }
keep_next_level (); keep_next_level ();
$<ttype>$ = expand_start_stmt_expr (); } if (!processing_template_decl)
$<ttype>$ = expand_start_stmt_expr ();
else
$<ttype>$ = NULL_TREE;
}
compstmt ')' compstmt ')'
{ tree rtl_exp; { tree rtl_exp;
if (pedantic) if (pedantic)
pedwarn ("ANSI C++ forbids braced-groups within expressions"); pedwarn ("ANSI C++ forbids braced-groups within expressions");
if (!processing_template_decl)
{
rtl_exp = expand_end_stmt_expr ($<ttype>2); rtl_exp = expand_end_stmt_expr ($<ttype>2);
/* The statements have side effects, so the group does. */ /* The statements have side effects, so the
group does. */
TREE_SIDE_EFFECTS (rtl_exp) = 1; TREE_SIDE_EFFECTS (rtl_exp) = 1;
}
if (TREE_CODE ($3) == BLOCK) if (TREE_CODE ($3) == BLOCK)
{ {
/* Make a BIND_EXPR for the BLOCK already made. */ /* Make a BIND_EXPR for the BLOCK already made. */
if (processing_template_decl)
$$ = build (BIND_EXPR, NULL_TREE,
NULL_TREE, last_tree, $3);
else
$$ = build (BIND_EXPR, TREE_TYPE (rtl_exp), $$ = build (BIND_EXPR, TREE_TYPE (rtl_exp),
NULL_TREE, rtl_exp, $3); NULL_TREE, rtl_exp, $3);
/* Remove the block from the tree at this point. /* Remove the block from the tree at this point.
It gets put back at the proper place It gets put back at the proper place
when the BIND_EXPR is expanded. */ when the BIND_EXPR is expanded. */
......
...@@ -4121,13 +4121,34 @@ tsubst_copy (t, args, nargs, in_decl) ...@@ -4121,13 +4121,34 @@ tsubst_copy (t, args, nargs, in_decl)
NULL_TREE); NULL_TREE);
} }
case BIND_EXPR:
case COND_EXPR: case COND_EXPR:
case MODOP_EXPR: case MODOP_EXPR:
return build_nt {
tree r = build_nt
(code, tsubst_copy (TREE_OPERAND (t, 0), args, nargs, in_decl), (code, tsubst_copy (TREE_OPERAND (t, 0), args, nargs, in_decl),
tsubst_copy (TREE_OPERAND (t, 1), args, nargs, in_decl), tsubst_copy (TREE_OPERAND (t, 1), args, nargs, in_decl),
tsubst_copy (TREE_OPERAND (t, 2), args, nargs, in_decl)); tsubst_copy (TREE_OPERAND (t, 2), args, nargs, in_decl));
if (code == BIND_EXPR && !processing_template_decl)
{
/* This processing should really occur in tsubst_expr,
However, tsubst_expr does not recurse into expressions,
since it assumes that there aren't any statements
inside them. Instead, it simply calls
build_expr_from_tree. So, we need to expand the
BIND_EXPR here. */
tree rtl_exp = expand_start_stmt_expr();
tsubst_expr (TREE_OPERAND (r, 1), args, nargs, in_decl);
rtl_exp = expand_end_stmt_expr (rtl_exp);
TREE_SIDE_EFFECTS (rtl_exp) = 1;
return build (BIND_EXPR, TREE_TYPE (rtl_exp),
NULL_TREE, rtl_exp, TREE_OPERAND (r, 2));
}
return r;
}
case NEW_EXPR: case NEW_EXPR:
{ {
tree r = build_nt tree r = build_nt
......
...@@ -1645,6 +1645,13 @@ mapcar (t, func) ...@@ -1645,6 +1645,13 @@ mapcar (t, func)
case TEMPLATE_TEMPLATE_PARM: case TEMPLATE_TEMPLATE_PARM:
return copy_template_template_parm (t); return copy_template_template_parm (t);
case BIND_EXPR:
t = copy_node (t);
TREE_OPERAND (t, 0) = mapcar (TREE_OPERAND (t, 0), func);
TREE_OPERAND (t, 1) = mapcar (TREE_OPERAND (t, 1), func);
TREE_OPERAND (t, 2) = NULL_TREE;
return t;
case RECORD_TYPE: case RECORD_TYPE:
if (TYPE_PTRMEMFUNC_P (t)) if (TYPE_PTRMEMFUNC_P (t))
return build_ptrmemfunc_type return build_ptrmemfunc_type
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment