diff options
Diffstat (limited to 'gcc/cp/init.c')
-rw-r--r-- | gcc/cp/init.c | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 131da1a..1381a23 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -247,9 +247,12 @@ build_zero_init_1 (tree type, tree nelts, bool static_storage_p, /* Iterate over the array elements, building initializations. */ if (nelts) - max_index = fold_build2_loc (input_location, - MINUS_EXPR, TREE_TYPE (nelts), - nelts, integer_one_node); + max_index = fold_build2_loc (input_location, MINUS_EXPR, + TREE_TYPE (nelts), nelts, + build_one_cst (TREE_TYPE (nelts))); + /* Treat flexible array members like [0] arrays. */ + else if (TYPE_DOMAIN (type) == NULL_TREE) + max_index = build_minus_one_cst (sizetype); else max_index = array_type_nelts (type); @@ -261,20 +264,19 @@ build_zero_init_1 (tree type, tree nelts, bool static_storage_p, /* A zero-sized array, which is accepted as an extension, will have an upper bound of -1. */ - if (!tree_int_cst_equal (max_index, integer_minus_one_node)) + if (!integer_minus_onep (max_index)) { constructor_elt ce; /* If this is a one element array, we just use a regular init. */ - if (tree_int_cst_equal (size_zero_node, max_index)) + if (integer_zerop (max_index)) ce.index = size_zero_node; else ce.index = build2 (RANGE_EXPR, sizetype, size_zero_node, - max_index); + max_index); - ce.value = build_zero_init_1 (TREE_TYPE (type), - /*nelts=*/NULL_TREE, - static_storage_p, NULL_TREE); + ce.value = build_zero_init_1 (TREE_TYPE (type), /*nelts=*/NULL_TREE, + static_storage_p, NULL_TREE); if (ce.value) { vec_alloc (v, 1); |