return false;
}
+/* Return number of initialized elements in CTOR. */
+
+static unsigned HOST_WIDE_INT
+count_ctor_elements (tree ctor)
+{
+ unsigned HOST_WIDE_INT len = 0;
+ for (constructor_elt &e: CONSTRUCTOR_ELTS (ctor))
+ if (TREE_CODE (e.value) == RAW_DATA_CST)
+ len += RAW_DATA_LENGTH (e.value);
+ else
+ ++len;
+ return len;
+}
+
/* We're initializing an array of ELTTYPE from INIT. If it seems useful,
return INIT as an array (of its own type) so the caller can initialize the
target array in a loop. */
if (!is_xible (INIT_EXPR, elttype, copy_argtypes))
return NULL_TREE;
- tree arr = build_array_of_n_type (init_elttype, CONSTRUCTOR_NELTS (init));
+ unsigned HOST_WIDE_INT len = count_ctor_elements (init);
+ tree arr = build_array_of_n_type (init_elttype, len);
arr = finish_compound_literal (arr, init, tf_none);
DECL_MERGEABLE (TARGET_EXPR_SLOT (arr)) = true;
return arr;
{
/* Conversion to std::initializer_list<T>. */
tree elttype = TREE_VEC_ELT (CLASSTYPE_TI_ARGS (totype), 0);
- unsigned len = CONSTRUCTOR_NELTS (expr);
+ unsigned HOST_WIDE_INT len = CONSTRUCTOR_NELTS (expr);
tree array;
if (tree init = maybe_init_list_as_array (elttype, expr))
elttype
= cp_build_qualified_type (elttype, (cp_type_quals (elttype)
| TYPE_QUAL_CONST));
- array = build_array_of_n_type (elttype, len);
+ tree index_type = TYPE_DOMAIN (TREE_TYPE (init));
+ array = build_cplus_array_type (elttype, index_type);
+ len = TREE_INT_CST_LOW (TYPE_MAX_VALUE (index_type)) + 1;
array = build_vec_init_expr (array, init, complain);
array = get_target_expr (array);
array = cp_build_addr_expr (array, complain);
--- /dev/null
+// PR c++/118124
+// { dg-do compile { target c++11 } }
+// { dg-options "-O2" }
+
+namespace std {
+template <class T> struct initializer_list {
+private:
+ const T *_M_array;
+ decltype (sizeof 0) _M_len;
+};
+}
+struct B {
+ B (int);
+};
+struct A {
+ A (std::initializer_list<B>);
+};
+A a { 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7,
+ 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1,
+ 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3,
+ 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5,
+ 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5 };