Hi,

looks like the __bases extensions need some work as regards error checking / recovery but this specific ICE on invalid seems easy and safe to fix: check that TYPE_BINFO isn't null and handle the possibility of vector->length () null during error recovery.

Tested x86_64-linux.

Thanks,
Paolo.

/////////////////
/cp
2015-01-19  Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/60218
        * semantics.c (calculate_bases_helper): Don't call dfs_walk_all
        when TYPE_BINFO (type) is null.
        (calculate_bases): Handle gracefully a null vector->length ().

/testsuite
2015-01-19  Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/60218
        * g++.dg/ext/bases2.C: New.
Index: cp/semantics.c
===================================================================
--- cp/semantics.c      (revision 219849)
+++ cp/semantics.c      (working copy)
@@ -3804,8 +3804,9 @@ calculate_bases_helper (tree type)
   vec<tree, va_gc> *vector = make_tree_vector();
 
   /* Now add non-virtual base classes in order of construction */
-  dfs_walk_all (TYPE_BINFO (type),
-                dfs_calculate_bases_pre, dfs_calculate_bases_post, &vector);
+  if (TYPE_BINFO (type))
+    dfs_walk_all (TYPE_BINFO (type),
+                 dfs_calculate_bases_pre, dfs_calculate_bases_post, &vector);
   return vector;
 }
 
@@ -3839,13 +3840,18 @@ calculate_bases (tree type)
   vec_safe_splice (vector, nonvbases);
   release_tree_vector (nonvbases);
 
-  /* Last element is entire class, so don't copy */
-  bases_vec = make_tree_vec (vector->length () - 1);
+  /* NB: vector->length () can even be zero during error recovery.  */
+  if (vector->length () > 1)
+    {
+      /* Last element is entire class, so don't copy */
+      bases_vec = make_tree_vec (vector->length() - 1);
 
-  for (i = 0; i < vector->length () - 1; ++i)
-    {
-      TREE_VEC_ELT (bases_vec, i) = (*vector)[i];
+      for (i = 0; i < vector->length () - 1; ++i)
+       TREE_VEC_ELT (bases_vec, i) = (*vector)[i];
     }
+  else
+    bases_vec = make_tree_vec (0);
+
   release_tree_vector (vector);
   return bases_vec;
 }
Index: testsuite/g++.dg/ext/bases2.C
===================================================================
--- testsuite/g++.dg/ext/bases2.C       (revision 0)
+++ testsuite/g++.dg/ext/bases2.C       (working copy)
@@ -0,0 +1,14 @@
+// PR c++/60218
+// { dg-do compile { target c++11 } }
+
+template<typename...> struct A {};
+
+template<typename T> struct B
+{
+  typedef A<__bases(T)...> C;
+};
+
+struct X {};
+struct Y : X* {};  // { dg-error "expected" }
+
+B<Y> b;

Reply via email to