]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/56291 (ICE for C++11 in output_constructor_regular_field, at varasm.c:4821)
authorJason Merrill <jason@redhat.com>
Tue, 12 Feb 2013 17:40:32 +0000 (12:40 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Tue, 12 Feb 2013 17:40:32 +0000 (12:40 -0500)
PR c++/56291
* semantics.c (sort_constexpr_mem_initializers): Handle
vptr out of order.

From-SVN: r195987

gcc/cp/ChangeLog
gcc/cp/semantics.c
gcc/testsuite/g++.dg/cpp0x/constexpr-virtual4.C [new file with mode: 0644]

index a9288cd6981a61b8557ad2c820d0a4d5da816671..de88e1161c2827d946031b73d2bbf42ab160acac 100644 (file)
@@ -1,3 +1,9 @@
+2013-02-12  Jason Merrill  <jason@redhat.com>
+
+       PR c++/56291
+       * semantics.c (sort_constexpr_mem_initializers): Handle
+       vptr out of order.
+
 2013-02-11  Jason Merrill  <jason@redhat.com>
 
        PR c++/56268
index bde24d34ca1b046b545c058ec398d46c2b247df7..da0b48faed17f4f4f2781499eb9415d963cf9cc7 100644 (file)
@@ -5885,31 +5885,38 @@ check_constexpr_ctor_body (tree last, tree list)
 /* VEC is a vector of constructor elements built up for the base and member
    initializers of a constructor for TYPE.  They need to be in increasing
    offset order, which they might not be yet if TYPE has a primary base
-   which is not first in the base-clause.  */
+   which is not first in the base-clause or a vptr and at least one base
+   all of which are non-primary.  */
 
 static VEC(constructor_elt,gc) *
 sort_constexpr_mem_initializers (tree type, VEC(constructor_elt,gc) *vec)
 {
   tree pri = CLASSTYPE_PRIMARY_BINFO (type);
+  tree field_type;
   constructor_elt elt;
   int i;
 
-  if (pri == NULL_TREE
-      || pri == BINFO_BASE_BINFO (TYPE_BINFO (type), 0))
+  if (pri)
+    field_type = BINFO_TYPE (pri);
+  else if (TYPE_CONTAINS_VPTR_P (type))
+    field_type = vtbl_ptr_type_node;
+  else
     return vec;
 
-  /* Find the element for the primary base and move it to the beginning of
-     the vec.  */
-  pri = BINFO_TYPE (pri);
-  for (i = 1; ; ++i)
-    if (TREE_TYPE (VEC_index (constructor_elt, vec, i)->index) == pri)
+  /* Find the element for the primary base or vptr and move it to the
+     beginning of the vec.  */
+  for (i = 0; ; ++i)
+    if (TREE_TYPE (VEC_index (constructor_elt, vec, i)->index) == field_type)
       break;
 
-  elt = *VEC_index (constructor_elt, vec, i);
-  for (; i > 0; --i)
-    VEC_replace (constructor_elt, vec, i,
-                VEC_index (constructor_elt, vec, i-1));
-  VEC_replace (constructor_elt, vec, 0, &elt);
+  if (i > 0)
+    {
+      elt = *VEC_index (constructor_elt, vec, i);
+      for (; i > 0; --i)
+       VEC_replace (constructor_elt, vec, i,
+                    VEC_index (constructor_elt, vec, i-1));
+      VEC_replace (constructor_elt, vec, 0, &elt);
+    }
   return vec;
 }
 
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-virtual4.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-virtual4.C
new file mode 100644 (file)
index 0000000..32cee96
--- /dev/null
@@ -0,0 +1,18 @@
+// PR c++/56291
+// { dg-options -std=c++11 }
+
+class Base
+{
+public:
+ constexpr Base() : v(1) {};
+ int v;
+};
+
+class Derived : public Base
+{
+public:
+ constexpr Derived() : Base() {};
+ virtual void function();
+};
+
+Derived d;