TYPE, as described in [dcl.init]. */
tree
-build_value_init (tree type)
+build_value_init (tree type, tsubst_flags_t complain)
{
/* [dcl.init]
(type,
build_special_member_call (NULL_TREE, complete_ctor_identifier,
NULL, type, LOOKUP_NORMAL,
- tf_warning_or_error));
+ complain));
else if (TREE_CODE (type) != UNION_TYPE && TYPE_NEEDS_CONSTRUCTING (type))
{
/* This is a class that needs constructing, but doesn't have
This will be handled in simplify_aggr_init_expr. */
tree ctor = build_special_member_call
(NULL_TREE, complete_ctor_identifier,
- NULL, type, LOOKUP_NORMAL, tf_warning_or_error);
+ NULL, type, LOOKUP_NORMAL, complain);
ctor = build_aggr_init_expr (type, ctor);
AGGR_INIT_ZERO_FIRST (ctor) = 1;
return ctor;
}
}
- return build_value_init_noctor (type);
+ return build_value_init_noctor (type, complain);
}
/* Like build_value_init, but don't call the constructor for TYPE. Used
for base initializers. */
tree
-build_value_init_noctor (tree type)
+build_value_init_noctor (tree type, tsubst_flags_t complain)
{
if (CLASS_TYPE_P (type))
{
ftype = TREE_TYPE (field);
if (TREE_CODE (ftype) == REFERENCE_TYPE)
- error ("value-initialization of reference");
+ {
+ if (complain & tf_error)
+ error ("value-initialization of reference");
+ else
+ return error_mark_node;
+ }
/* We could skip vfields and fields of types with
user-defined constructors, but I think that won't improve
corresponding to base classes as well. Thus, iterating
over TYPE_FIELDs will result in correct initialization of
all of the subobjects. */
- value = build_value_init (ftype);
+ value = build_value_init (ftype, complain);
if (value)
CONSTRUCTOR_APPEND_ELT(v, field, value);
/* If we have an error_mark here, we should just return error mark
as we don't know the size of the array yet. */
if (max_index == error_mark_node)
- return error_mark_node;
+ {
+ error ("cannot value-initialize array of unknown bound %qT", type);
+ return error_mark_node;
+ }
gcc_assert (TREE_CODE (max_index) == INTEGER_CST);
/* A zero-sized array, which is accepted as an extension, will
ce->index = build2 (RANGE_EXPR, sizetype, size_zero_node,
max_index);
- ce->value = build_value_init (TREE_TYPE (type));
+ ce->value = build_value_init (TREE_TYPE (type), complain);
/* The gimplifier can't deal with a RANGE_EXPR of TARGET_EXPRs. */
gcc_assert (TREE_CODE (ce->value) != TARGET_EXPR
member);
else
{
- init = build2 (INIT_EXPR, type, decl, build_value_init (type));
+ init = build2 (INIT_EXPR, type, decl,
+ build_value_init (type, tf_warning_or_error));
finish_expr_stmt (init);
}
}
else if (TREE_CODE (init) == TREE_LIST)
/* There was an explicit member initialization. Do some work
in that case. */
- init = build_x_compound_expr_from_list (init, ELK_MEM_INIT);
+ init = build_x_compound_expr_from_list (init, ELK_MEM_INIT,
+ tf_warning_or_error);
if (init)
finish_expr_stmt (cp_build_modify_expr (decl, INIT_EXPR, init,
then just zero out the object and we're done. */
else
{
- init = build2 (INIT_EXPR, type, exp, build_value_init_noctor (type));
+ init = build2 (INIT_EXPR, type, exp,
+ build_value_init_noctor (type, complain));
finish_expr_stmt (init);
return;
}
else if (explicit_value_init_p)
{
/* Something like `new int()'. */
- init_expr = build2 (INIT_EXPR, type,
- init_expr, build_value_init (type));
+ tree val = build_value_init (type, complain);
+ if (val == error_mark_node)
+ return error_mark_node;
+ init_expr = build2 (INIT_EXPR, type, init_expr, val);
}
else
{
/* The type allocated must be complete. If the new-type-id was
"T[N]" then we are just checking that "T" is complete here, but
that is equivalent, since the value of "N" doesn't matter. */
- if (!complete_type_or_else (type, NULL_TREE))
+ if (!complete_type_or_maybe_complain (type, NULL_TREE, complain))
return error_mark_node;
rval = build_new_1 (placement, type, nelts, init, use_global_new, complain);
0, complain);
}
else if (explicit_value_init_p)
- elt_init = build2 (INIT_EXPR, type, to,
- build_value_init (type));
+ {
+ elt_init = build_value_init (type, complain);
+ if (elt_init == error_mark_node)
+ return error_mark_node;
+ else
+ elt_init = build2 (INIT_EXPR, type, to, elt_init);
+ }
else
{
gcc_assert (TYPE_NEEDS_CONSTRUCTING (type));