The user *should* have been using <initializer_list>. But responding to this with an ICE isn't acceptable either.
We do reject wholly incompatible user-defined initializer_list: finish_struct requires it be a template with a pointer field followed by an integer field, and in this case it is, but convert_like_real assumes that the second integer field has a size_type, so it initializes the length with that type. But as the following testcase (which clang accepts) shows, it might be a different integer type, and gimplifier doesn't like any non-trivial conversion in an assignment. This fixes only a part of the PR. Bootstrapped/regtested on x86_64-linux, ok for trunk? 2015-03-31 Marek Polacek <pola...@redhat.com> PR c++/65554 * call.c (convert_like_real): Build integer constant with the field type, not always of size_type. * g++.dg/cpp0x/initlist93.C: New test. diff --git gcc/cp/call.c gcc/cp/call.c index 31d2b9c..b171179 100644 --- gcc/cp/call.c +++ gcc/cp/call.c @@ -6366,7 +6366,8 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum, field = next_initializable_field (TYPE_FIELDS (totype)); CONSTRUCTOR_APPEND_ELT (vec, field, array); field = next_initializable_field (DECL_CHAIN (field)); - CONSTRUCTOR_APPEND_ELT (vec, field, size_int (len)); + CONSTRUCTOR_APPEND_ELT (vec, field, + build_int_cst (TREE_TYPE (field), len)); new_ctor = build_constructor (totype, vec); return get_target_expr_sfinae (new_ctor, complain); } diff --git gcc/testsuite/g++.dg/cpp0x/initlist93.C gcc/testsuite/g++.dg/cpp0x/initlist93.C index e69de29..230e2f9 100644 --- gcc/testsuite/g++.dg/cpp0x/initlist93.C +++ gcc/testsuite/g++.dg/cpp0x/initlist93.C @@ -0,0 +1,26 @@ +// PR c++/65554 +// { dg-do compile { target c++11 } } + +namespace std +{ +template <class> class initializer_list +{ + int *_M_array; + int _M_len; +}; +class A +{ +public: + void operator=(initializer_list<int>); +}; +class B +{ + void m_fn1 (A &) const; +}; +void +B::m_fn1 (A &) const +{ + A extra; + extra = {}; +} +} Marek