* c-common.h (add_decl_stmt): Move to cp-tree.h.
* c-decl.c (finish_decl): Don't use add_decl_stmt.
* c-parse.in: Likewise.
* c-gimplify.c (gimplify_expr_stmt): Don't build CLEANUP_POINT_EXPR.
(gimplify_c_loop, gimplify_return_stmt, gimplify_decl_stmt): Likewise.
* c-semantics.c (add_decl_stmt): Move to cp/semantics.c.
cp/
* cp-tree.h (add_decl_stmt): Declare.
* pt.c (tsubst_copy): Abort for CLEANUP_POINT_EXPR.
* semantics.c (maybe_cleanup_point_expr): New.
(add_decl_stmt, finish_expr_stmt, finish_return_stmt,
finish_for_expr, finish_switch_cond): Use it.
(finalize_nrv_r): Don't build an EXPR_STMT. Don't frob TREE_CHAIN.
From-SVN: r83409
+2004-06-20 Richard Henderson <rth@redhat.com>
+
+ * c-common.h (add_decl_stmt): Move to cp-tree.h.
+ * c-decl.c (finish_decl): Don't use add_decl_stmt.
+ * c-parse.in: Likewise.
+ * c-gimplify.c (gimplify_expr_stmt): Don't build CLEANUP_POINT_EXPR.
+ (gimplify_c_loop, gimplify_return_stmt, gimplify_decl_stmt): Likewise.
+ * c-semantics.c (add_decl_stmt): Move to cp/semantics.c.
+
2004-06-20 Richard Henderson <rth@redhat.com>
* c-common.def (IF_STMT, CLEANUP_STMT): Move to cp-tree.def.
extern tree re_push_stmt_list (tree);
extern tree pop_stmt_list (tree);
extern tree add_stmt (tree);
-extern void add_decl_stmt (tree);
extern void push_cleanup (tree, tree, bool);
extern tree walk_stmt_tree (tree *, walk_tree_fn, void *);
}
if (TREE_CODE (decl) != FUNCTION_DECL)
- add_decl_stmt (decl);
+ add_stmt (build_stmt (DECL_STMT, decl));
}
if (!DECL_FILE_SCOPE_P (decl))
{
if (!DECL_FILE_SCOPE_P (decl)
&& variably_modified_type_p (TREE_TYPE (decl)))
- add_decl_stmt (decl);
+ add_stmt (build_stmt (DECL_STMT, decl));
rest_of_decl_compilation (decl, NULL, DECL_FILE_SCOPE_P (decl), 0);
}
if (stmt == NULL_TREE)
stmt = build_empty_stmt ();
- else if (stmts_are_full_exprs_p ())
- stmt = build1 (CLEANUP_POINT_EXPR, void_type_node, stmt);
*stmt_p = stmt;
cont_block = begin_bc_block (bc_continue);
gimplify_stmt (&body);
- if (incr && stmts_are_full_exprs_p ())
- incr = fold (build1 (CLEANUP_POINT_EXPR, void_type_node, incr));
gimplify_stmt (&incr);
body = finish_bc_block (cont_block, body);
{
tree expr = RETURN_STMT_EXPR (*stmt_p);
expr = build1 (RETURN_EXPR, void_type_node, expr);
- if (stmts_are_full_exprs_p ())
- expr = build1 (CLEANUP_POINT_EXPR, void_type_node, expr);
*stmt_p = expr;
return GS_OK;
}
DECL_INITIAL (decl) = NULL_TREE;
init = build (MODIFY_EXPR, void_type_node, decl, init);
- if (stmts_are_full_exprs_p ())
- init = build1 (CLEANUP_POINT_EXPR, void_type_node, init);
append_to_compound_expr (init, &pre);
}
else
add_stmt ($6);
finish_function ();
pop_function_context ();
- add_decl_stmt (decl); }
+ add_stmt (build_stmt (DECL_STMT, decl)); }
;
notype_nested_function:
add_stmt ($6);
finish_function ();
pop_function_context ();
- add_decl_stmt (decl); }
+ add_stmt (build_stmt (DECL_STMT, decl)); }
;
/* Any kind of declarator (thus, all declarators allowed
{
tree label = declare_label (TREE_VALUE (link));
C_DECLARED_LABEL_FLAG (label) = 1;
- add_decl_stmt (label);
+ add_stmt (build_stmt (DECL_STMT, label));
}
}
;
return t;
}
-/* Create a declaration statement for the declaration given by the
- DECL. */
-
-void
-add_decl_stmt (tree decl)
-{
- tree decl_stmt;
-
- /* We need the type to last until instantiation time. */
- decl_stmt = build_stmt (DECL_STMT, decl);
- add_stmt (decl_stmt);
-}
-
/* Build a generic statement based on the given type of node and
arguments. Similar to `build_nt', except that we set
EXPR_LOCUS to be the current source location. */
+2004-06-20 Richard Henderson <rth@redhat.com>
+
+ * cp-tree.h (add_decl_stmt): Declare.
+ * pt.c (tsubst_copy): Abort for CLEANUP_POINT_EXPR.
+ * semantics.c (maybe_cleanup_point_expr): New.
+ (add_decl_stmt, finish_expr_stmt, finish_return_stmt,
+ finish_for_expr, finish_switch_cond): Use it.
+ (finalize_nrv_r): Don't build an EXPR_STMT. Don't frob TREE_CHAIN.
+
2004-06-20 Richard Henderson <rth@redhat.com>
* cp-tree.def (CLEANUP_STMT, IF_STMT): Move from c-common.def.
extern void perform_deferred_access_checks (void);
extern void perform_or_defer_access_check (tree, tree);
extern void init_cp_semantics (void);
+extern void add_decl_stmt (tree);
extern tree finish_expr_stmt (tree);
extern tree begin_if_stmt (void);
extern void finish_if_stmt_cond (tree, tree);
in_decl),
tsubst (TREE_TYPE (t), args, complain, in_decl));
+ case CLEANUP_POINT_EXPR:
+ /* We shouldn't have built any of these during initial template
+ generation. Instead, they should be built during instantiation
+ in response to the saved STMT_IS_FULL_EXPR_P setting. */
+ abort ();
+
default:
return t;
}
: &scope_chain->x_stmt_tree);
}
+/* If statements are full expressions, wrap STMT in a CLEANUP_POINT_EXPR. */
+
+static tree
+maybe_cleanup_point_expr (tree expr)
+{
+ if (!processing_template_decl && stmts_are_full_exprs_p ())
+ expr = fold (build1 (CLEANUP_POINT_EXPR, TREE_TYPE (expr), expr));
+ return expr;
+}
+
+/* Create a declaration statement for the declaration given by the DECL. */
+
+void
+add_decl_stmt (tree decl)
+{
+ tree r = build_stmt (DECL_STMT, decl);
+ if (DECL_INITIAL (decl))
+ r = maybe_cleanup_point_expr (r);
+ add_stmt (r);
+}
+
/* Nonzero if TYPE is an anonymous union or struct type. We have to use a
flag for this because "A union for which objects or pointers are
declared is not an anonymous union" [class.union]. */
/* Simplification of inner statement expressions, compound exprs,
etc can result in the us already having an EXPR_STMT. */
- if (TREE_CODE (expr) != EXPR_STMT)
- expr = build_stmt (EXPR_STMT, expr);
+ if (TREE_CODE (expr) != CLEANUP_POINT_EXPR)
+ {
+ if (TREE_CODE (expr) != EXPR_STMT)
+ expr = build_stmt (EXPR_STMT, expr);
+ expr = maybe_cleanup_point_expr (expr);
+ }
+
r = add_stmt (expr);
}
return finish_goto_stmt (dtor_label);
}
}
- r = add_stmt (build_stmt (RETURN_STMT, expr));
+
+ r = build_stmt (RETURN_STMT, expr);
+ r = maybe_cleanup_point_expr (r);
+ r = add_stmt (r);
finish_stmt ();
return r;
void
finish_for_expr (tree expr, tree for_stmt)
{
+ if (!expr)
+ return;
/* If EXPR is an overloaded function, issue an error; there is no
context available to use to perform overload resolution. */
- if (expr && type_unknown_p (expr))
+ if (type_unknown_p (expr))
{
cxx_incomplete_type_error (expr, TREE_TYPE (expr));
expr = error_mark_node;
}
+ expr = maybe_cleanup_point_expr (expr);
FOR_EXPR (for_stmt) = expr;
}
Integral promotions are performed. */
cond = perform_integral_promotions (cond);
- cond = fold (build1 (CLEANUP_POINT_EXPR, TREE_TYPE (cond), cond));
+ cond = maybe_cleanup_point_expr (cond);
}
if (cond != error_mark_node)
init = TREE_OPERAND (target_expr, 1);
type = TREE_TYPE (init);
- if (stmts_are_full_exprs_p ())
- init = fold (build1 (CLEANUP_POINT_EXPR, type, init));
+ init = maybe_cleanup_point_expr (init);
*result_stmt_p = init;
if (VOID_TYPE_P (type))
DECL_INITIAL (dp->var) = error_mark_node;
}
else
- init = NULL_TREE;
- init = build_stmt (EXPR_STMT, init);
+ init = build_empty_stmt ();
SET_EXPR_LOCUS (init, EXPR_LOCUS (*tp));
- TREE_CHAIN (init) = TREE_CHAIN (*tp);
*tp = init;
}
/* And replace all uses of the NRV with the RESULT_DECL. */