On Tue, Mar 31, 2015 at 03:11:24PM -0400, Jason Merrill wrote: > On 03/31/2015 01:22 PM, Marek Polacek wrote: > >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. > > I think I'd prefer to enforce that the second integer is size_t, not just an > integer, so that the assumption in convert_like_real is correct.
Ok, that isn't hard to do either. Bootstrapped/regtested on x86_64-linux, ok for trunk? 2015-04-01 Marek Polacek <pola...@redhat.com> PR c++/65554 * class.c (finish_struct): Require that the second field of a user-defined initializer_list be of size type. * g++.dg/cpp0x/initlist93.C: New test. * g++.dg/cpp0x/initlist94.C: New test. diff --git gcc/cp/class.c gcc/cp/class.c index c2d4201..9f189fb 100644 --- gcc/cp/class.c +++ gcc/cp/class.c @@ -6891,7 +6891,7 @@ finish_struct (tree t, tree attributes) if (f && TREE_CODE (TREE_TYPE (f)) == POINTER_TYPE) { f = next_initializable_field (DECL_CHAIN (f)); - if (f && TREE_CODE (TREE_TYPE (f)) == INTEGER_TYPE) + if (f && same_type_p (TREE_TYPE (f), size_type_node)) ok = true; } } diff --git gcc/testsuite/g++.dg/cpp0x/initlist93.C gcc/testsuite/g++.dg/cpp0x/initlist93.C index e69de29..84a4738 100644 --- gcc/testsuite/g++.dg/cpp0x/initlist93.C +++ gcc/testsuite/g++.dg/cpp0x/initlist93.C @@ -0,0 +1,13 @@ +// PR c++/65554 +// { dg-do compile { target c++11 } } + +namespace std +{ +template <class> class initializer_list // { dg-error "definition of std::initializer_list does not match" } +{ + int *_M_array; + int _M_len; +}; +} + +// { dg-prune-output "compilation terminated" } diff --git gcc/testsuite/g++.dg/cpp0x/initlist94.C gcc/testsuite/g++.dg/cpp0x/initlist94.C index e69de29..f83a81d 100644 --- gcc/testsuite/g++.dg/cpp0x/initlist94.C +++ gcc/testsuite/g++.dg/cpp0x/initlist94.C @@ -0,0 +1,13 @@ +// PR c++/65554 +// { dg-do compile { target c++11 } } + +typedef decltype (sizeof (int)) size_type; + +namespace std +{ +template <class> class initializer_list +{ + int *_M_array; + size_type _M_len; +}; +} Marek