2016-04-14 Jason Merrill <jason@redhat.com>
+ PR c++/70494
+ * decl.c (cxx_maybe_build_cleanup): Handle non-decls.
+ * typeck2.c (split_nonconstant_init_1): Use it.
+
PR c++/70528
* class.c (type_has_constexpr_default_constructor): Return true
for an implicitly declared constructor.
/* If DECL is of a type which needs a cleanup, build and return an
expression to perform that cleanup here. Return NULL_TREE if no
- cleanup need be done. */
+ cleanup need be done. DECL can also be a _REF when called from
+ split_nonconstant_init_1. */
tree
cxx_maybe_build_cleanup (tree decl, tsubst_flags_t complain)
/* Handle "__attribute__((cleanup))". We run the cleanup function
before the destructor since the destructor is what actually
terminates the lifetime of the object. */
- attr = lookup_attribute ("cleanup", DECL_ATTRIBUTES (decl));
+ if (DECL_P (decl))
+ attr = lookup_attribute ("cleanup", DECL_ATTRIBUTES (decl));
+ else
+ attr = NULL_TREE;
if (attr)
{
tree id;
protected_set_expr_location (cleanup, UNKNOWN_LOCATION);
if (cleanup
+ && DECL_P (decl)
&& !lookup_attribute ("warn_unused", TYPE_ATTRIBUTES (TREE_TYPE (decl)))
/* Treat objects with destructors as used; the destructor may do
something substantive. */
code = build_stmt (input_location, EXPR_STMT, code);
code = maybe_cleanup_point_expr_void (code);
add_stmt (code);
- if (type_build_dtor_call (inner_type))
- {
- code = (build_special_member_call
- (sub, complete_dtor_identifier, NULL, inner_type,
- LOOKUP_NORMAL, tf_warning_or_error));
- if (!TYPE_HAS_TRIVIAL_DESTRUCTOR (inner_type))
- finish_eh_cleanup (code);
- }
+ if (tree cleanup
+ = cxx_maybe_build_cleanup (sub, tf_warning_or_error))
+ finish_eh_cleanup (cleanup);
}
num_split_elts++;