Hi,
this regression is an ICE happening during error recovery: the loop in
sort_constexpr_mem_initializers tries to access the vector beyond its
end. Robustifying the whole thing, using in particular a standard
pattern using vec_safe_iterate to go through the vector, works. In case,
I'm not sure if we also want to add a gcc_assert on errorcount, maybe
right before the final conditional?!? Booted and tested x86_64-linux.
Thanks,
Paolo.
////////////////////
/cp
2014-04-04 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/58207
* semantics.c (sort_constexpr_mem_initializers): Robustify loop.
/testsuite
2014-04-04 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/58207
* g++.dg/cpp0x/constexpr-ice15.C: New.
Index: cp/semantics.c
===================================================================
--- cp/semantics.c (revision 209078)
+++ cp/semantics.c (working copy)
@@ -7717,8 +7717,8 @@ sort_constexpr_mem_initializers (tree type, vec<co
{
tree pri = CLASSTYPE_PRIMARY_BINFO (type);
tree field_type;
- constructor_elt elt;
- int i;
+ unsigned i;
+ constructor_elt *ce;
if (pri)
field_type = BINFO_TYPE (pri);
@@ -7729,14 +7729,14 @@ sort_constexpr_mem_initializers (tree type, vec<co
/* Find the element for the primary base or vptr and move it to the
beginning of the vec. */
- vec<constructor_elt, va_gc> &vref = *v;
- for (i = 0; ; ++i)
- if (TREE_TYPE (vref[i].index) == field_type)
+ for (i = 0; vec_safe_iterate (v, i, &ce); ++i)
+ if (TREE_TYPE (ce->index) == field_type)
break;
- if (i > 0)
+ if (i > 0 && i < vec_safe_length (v))
{
- elt = vref[i];
+ vec<constructor_elt, va_gc> &vref = *v;
+ constructor_elt elt = vref[i];
for (; i > 0; --i)
vref[i] = vref[i-1];
vref[0] = elt;
Index: testsuite/g++.dg/cpp0x/constexpr-ice15.C
===================================================================
--- testsuite/g++.dg/cpp0x/constexpr-ice15.C (revision 0)
+++ testsuite/g++.dg/cpp0x/constexpr-ice15.C (working copy)
@@ -0,0 +1,12 @@
+// PR c++/58207
+// { dg-do compile { target c++11 } }
+
+struct A
+{
+ virtual bool foo ();
+};
+
+struct B : public A
+{
+ constexpr B () : A (&::n) {} // { dg-error "declared" }
+};