X-Git-Url: http://git.sourceforge.jp/view?a=blobdiff_plain;f=gcc%2Fcp%2Finit.c;h=8555fadfb4213066ffba5a20c17137a507dcf617;hb=4c4e25630d07e18b14fdafeaaf5341e8c2da0530;hp=4e7cab382aafca1fd8310ceba9cdfa07787e3349;hpb=80e5473297f3b9131a8e689f9a60714e486c72fb;p=pf3gnuchains%2Fgcc-fork.git diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 4e7cab382aa..8555fadfb42 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -184,7 +184,7 @@ build_zero_init (tree type, tree nelts, bool static_storage_p) VEC(constructor_elt,gc) *v = NULL; /* Iterate over the fields, building initializations. */ - for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field)) + for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field)) { if (TREE_CODE (field) != FIELD_DECL) continue; @@ -269,7 +269,7 @@ build_zero_init (tree type, tree nelts, bool static_storage_p) TYPE, as described in [dcl.init]. */ tree -build_value_init (tree type) +build_value_init (tree type, tsubst_flags_t complain) { /* [dcl.init] @@ -302,7 +302,7 @@ build_value_init (tree type) (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 @@ -311,21 +311,21 @@ build_value_init (tree type) 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)) { @@ -337,7 +337,7 @@ build_value_init_noctor (tree type) VEC(constructor_elt,gc) *v = NULL; /* Iterate over the fields, building initializations. */ - for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field)) + for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field)) { tree ftype, value; @@ -347,7 +347,12 @@ build_value_init_noctor (tree 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 @@ -359,7 +364,7 @@ build_value_init_noctor (tree type) 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); @@ -379,7 +384,10 @@ build_value_init_noctor (tree type) /* 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 @@ -398,7 +406,7 @@ build_value_init_noctor (tree type) 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 @@ -456,7 +464,8 @@ perform_member_init (tree member, tree init) 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); } } @@ -525,7 +534,8 @@ perform_member_init (tree member, tree 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, @@ -562,27 +572,29 @@ build_field_list (tree t, tree list, int *uses_unions_p) if (TREE_CODE (t) == UNION_TYPE) *uses_unions_p = 1; - for (fields = TYPE_FIELDS (t); fields; fields = TREE_CHAIN (fields)) + for (fields = TYPE_FIELDS (t); fields; fields = DECL_CHAIN (fields)) { + tree fieldtype; + /* Skip CONST_DECLs for enumeration constants and so forth. */ if (TREE_CODE (fields) != FIELD_DECL || DECL_ARTIFICIAL (fields)) continue; + fieldtype = TREE_TYPE (fields); /* Keep track of whether or not any fields are unions. */ - if (TREE_CODE (TREE_TYPE (fields)) == UNION_TYPE) + if (TREE_CODE (fieldtype) == UNION_TYPE) *uses_unions_p = 1; /* For an anonymous struct or union, we must recursively consider the fields of the anonymous type. They can be directly initialized from the constructor. */ - if (ANON_AGGR_TYPE_P (TREE_TYPE (fields))) + if (ANON_AGGR_TYPE_P (fieldtype)) { /* Add this field itself. Synthesized copy constructors initialize the entire aggregate. */ list = tree_cons (fields, NULL_TREE, list); /* And now add the fields in the anonymous aggregate. */ - list = build_field_list (TREE_TYPE (fields), list, - uses_unions_p); + list = build_field_list (fieldtype, list, uses_unions_p); } /* Add this field. */ else if (DECL_NAME (fields)) @@ -718,7 +730,7 @@ sort_mem_initializers (tree t, tree mem_inits) for (p = &sorted_inits; *p; ) { tree field; - tree field_type; + tree ctx; int done; init = *p; @@ -736,13 +748,13 @@ sort_mem_initializers (tree t, tree mem_inits) /* See if this field is a member of a union, or a member of a structure contained in a union, etc. */ - for (field_type = DECL_CONTEXT (field); - !same_type_p (field_type, t); - field_type = TYPE_CONTEXT (field_type)) - if (TREE_CODE (field_type) == UNION_TYPE) + for (ctx = DECL_CONTEXT (field); + !same_type_p (ctx, t); + ctx = TYPE_CONTEXT (ctx)) + if (TREE_CODE (ctx) == UNION_TYPE) break; /* If this field is not a member of a union, skip it. */ - if (TREE_CODE (field_type) != UNION_TYPE) + if (TREE_CODE (ctx) != UNION_TYPE) goto next; /* If this union member has no explicit initializer, splice @@ -766,37 +778,37 @@ sort_mem_initializers (tree t, tree mem_inits) union { struct { int i; int j; }; }; initializing both `i' and `j' makes sense. */ - field_type = DECL_CONTEXT (field); + ctx = DECL_CONTEXT (field); done = 0; do { - tree last_field_type; + tree last_ctx; - last_field_type = DECL_CONTEXT (last_field); + last_ctx = DECL_CONTEXT (last_field); while (1) { - if (same_type_p (last_field_type, field_type)) + if (same_type_p (last_ctx, ctx)) { - if (TREE_CODE (field_type) == UNION_TYPE) + if (TREE_CODE (ctx) == UNION_TYPE) error_at (DECL_SOURCE_LOCATION (current_function_decl), "initializations for multiple members of %qT", - last_field_type); + last_ctx); done = 1; break; } - if (same_type_p (last_field_type, t)) + if (same_type_p (last_ctx, t)) break; - last_field_type = TYPE_CONTEXT (last_field_type); + last_ctx = TYPE_CONTEXT (last_ctx); } /* If we've reached the outermost class, then we're done. */ - if (same_type_p (field_type, t)) + if (same_type_p (ctx, t)) break; - field_type = TYPE_CONTEXT (field_type); + ctx = TYPE_CONTEXT (ctx); } while (!done); @@ -1028,7 +1040,7 @@ construct_virtual_base (tree vbase, tree arguments) in the outer block.) We trust the back end to figure out that the FLAG will not change across initializations, and avoid doing multiple tests. */ - flag = TREE_CHAIN (DECL_ARGUMENTS (current_function_decl)); + flag = DECL_CHAIN (DECL_ARGUMENTS (current_function_decl)); inner_if_stmt = begin_if_stmt (); finish_if_stmt_cond (flag, inner_if_stmt); @@ -1467,7 +1479,8 @@ expand_aggr_init_1 (tree binfo, tree true_exp, tree exp, tree init, int flags, 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; } @@ -1813,7 +1826,7 @@ diagnose_uninitialized_cst_or_ref_member_1 (tree type, tree origin, if (type_has_user_provided_constructor (type)) return 0; - for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field)) + for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field)) { tree field_type; @@ -2031,10 +2044,8 @@ build_new_1 (VEC(tree,gc) **placement, tree type, tree nelts, } alloc_fn = OVL_CURRENT (alloc_fn); class_addr = build1 (ADDR_EXPR, jclass_node, class_decl); - alloc_call = (cp_build_function_call - (alloc_fn, - build_tree_list (NULL_TREE, class_addr), - complain)); + alloc_call = cp_build_function_call_nary (alloc_fn, complain, + class_addr, NULL_TREE); } else if (TYPE_FOR_JAVA (elt_type) && MAYBE_CLASS_TYPE_P (elt_type)) { @@ -2310,8 +2321,10 @@ build_new_1 (VEC(tree,gc) **placement, tree type, tree nelts, 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 { @@ -2530,7 +2543,7 @@ build_new (VEC(tree,gc) **placement, tree type, tree nelts, /* 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); @@ -2576,7 +2589,7 @@ build_java_class_ref (tree type) /* Mangle the class$ field. */ { tree field; - for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field)) + for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field)) if (DECL_NAME (field) == CL_suffix) { mangle_decl (field); @@ -3037,8 +3050,13 @@ build_vec_init (tree base, tree maxindex, tree init, 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)); @@ -3381,7 +3399,7 @@ push_base_cleanups (void) return; for (member = TYPE_FIELDS (current_class_type); member; - member = TREE_CHAIN (member)) + member = DECL_CHAIN (member)) { tree this_type = TREE_TYPE (member); if (this_type == error_mark_node