Since a zero-length array is represented with a TYPE_MAX_VALUE of unsigned -1, iterating up from 0 takes a long time. So let's avoid that.
Tested x86_64-pc-linux-gnu, applying to trunk.
commit 237edb92e3aa09ad1eae62ed633bf161a8590bd7 Author: Jason Merrill <ja...@redhat.com> Date: Fri Jul 22 17:00:06 2016 -0400 PR c++/70709 - zero-length array member * class.c (walk_subobject_offsets): Handle 0-length array. diff --git a/gcc/cp/class.c b/gcc/cp/class.c index b2db7f8..b537b7e 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -4175,7 +4175,8 @@ walk_subobject_offsets (tree type, /* Avoid recursing into objects that are not interesting. */ if (!CLASS_TYPE_P (element_type) || !CLASSTYPE_CONTAINS_EMPTY_CLASS_P (element_type) - || !domain) + || !domain + || integer_minus_onep (TYPE_MAX_VALUE (domain))) return 0; /* Step through each of the elements in the array. */ diff --git a/gcc/testsuite/g++.dg/ext/array3.C b/gcc/testsuite/g++.dg/ext/array3.C new file mode 100644 index 0000000..e8940db --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/array3.C @@ -0,0 +1,19 @@ +// PR c++/70709 +// { dg-options "" } + +struct A +{ + A (int); +}; + +struct B +{ + B () {} + A a[0]; +}; + +struct C +{ + C () {} + B a[0]; +};