Patchwork C++ PATCH for c++/51029 (C++11 ICE with virtual base)

login
register
mail settings
Submitter Jason Merrill
Date Nov. 9, 2011, 6:12 p.m.
Message ID <4EBAC298.30606@redhat.com>
Download mbox | patch
Permalink /patch/124651/
State New
Headers show

Comments

Jason Merrill - Nov. 9, 2011, 6:12 p.m.
With this test, build_base_path was crashing because it (reasonably) 
assumed that if we're in a constructor with virtual bases, we can look 
at current_in_charge_parm.  But we can't in a template, even when we've 
cleared processing_template_decl for the sake of 
fold_non_dependent_expr.  So don't try.

Tested x86_64-pc-linux-gnu, applying to trunk.

Patch

commit b27a03c5dcd721810269a876fd7f91e0d5a068ba
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Nov 8 13:09:24 2011 -0500

    	PR c++/51029
    	* class.c (build_base_path): Don't ICE in fold_non_dependent_expr.

diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index f10a749..d2cf63c 100644
--- a/gcc/cp/class.c
+++ b/gcc/cp/class.c
@@ -359,6 +359,11 @@  build_base_path (enum tree_code code,
 	 V_BINFO.  That offset is an entry in D_BINFO's vtable.  */
       tree v_offset;
 
+      /* In a constructor template, current_in_charge_parm isn't set,
+	 and we might end up here via fold_non_dependent_expr.  */
+      if (fixed_type_p < 0 && !(cfun && current_in_charge_parm))
+	fixed_type_p = 0;
+
       if (fixed_type_p < 0 && in_base_initializer)
 	{
 	  /* In a base member initializer, we cannot rely on the
diff --git a/gcc/testsuite/g++.dg/template/virtual1.C b/gcc/testsuite/g++.dg/template/virtual1.C
new file mode 100644
index 0000000..ee86bf3
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/virtual1.C
@@ -0,0 +1,14 @@ 
+// PR c++/51029
+
+struct A
+{
+  void foo();
+};
+
+struct B : virtual A
+{
+  template<int> B()
+  {
+    foo();
+  }
+};