Patchwork C++ PATCH for c++/51620 (C++11 ICE with private dtor)

login
register
mail settings
Submitter Jason Merrill
Date Jan. 13, 2012, 3:50 p.m.
Message ID <4F1052D2.5020102@redhat.com>
Download mbox | patch
Permalink /patch/135909/
State New
Headers show

Comments

Jason Merrill - Jan. 13, 2012, 3:50 p.m.
Making a thunk to a deleted virtual function was making G++ very 
confused.  Fixed by using __cxa_deleted_virtual for deleted virtual 
functions, as specified by the ABI.

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

Patch

commit 2bf4059b4ebc1c1966b7b4ba94f520f7c0022ca0
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Jan 13 00:59:56 2012 -0500

    	PR c++/51620
    	* class.c (build_vtbl_initializer): Use __cxa_deleted_virtual.

diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index 58c89d3..9b957fe 100644
--- a/gcc/cp/class.c
+++ b/gcc/cp/class.c
@@ -8352,6 +8352,18 @@  build_vtbl_initializer (tree binfo,
 		  init = abort_fndecl_addr;
 		}
 	    }
+	  /* Likewise for deleted virtuals.  */
+	  else if (DECL_DELETED_FN (fn_original))
+	    {
+	      fn = get_identifier ("__cxa_deleted_virtual");
+	      if (!get_global_value_if_present (fn, &fn))
+		fn = push_library_fn (fn, (build_function_type_list
+					   (void_type_node, NULL_TREE)),
+				      NULL_TREE);
+	      if (!TARGET_VTABLE_USES_DESCRIPTORS)
+		init = fold_convert (vfunc_ptr_type_node,
+				     build_fold_addr_expr (fn));
+	    }
 	  else
 	    {
 	      if (!integer_zerop (delta) || vcall_index)
diff --git a/gcc/testsuite/g++.dg/cpp0x/defaulted34.C b/gcc/testsuite/g++.dg/cpp0x/defaulted34.C
new file mode 100644
index 0000000..0821992
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/defaulted34.C
@@ -0,0 +1,10 @@ 
+// { dg-options -std=c++0x }
+// { dg-final { scan-assembler "__cxa_deleted_virtual" } }
+
+struct A
+{
+  virtual void f();
+  virtual ~A() = delete;
+};
+
+void A::f() {}
diff --git a/gcc/testsuite/g++.dg/template/virtual3.C b/gcc/testsuite/g++.dg/template/virtual3.C
new file mode 100644
index 0000000..9fcfc45
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/virtual3.C
@@ -0,0 +1,11 @@ 
+// PR c++/51620
+
+template<int> class A
+{
+  virtual ~A();			// { dg-error "non-deleted|private" }
+};
+
+struct B : A<0>, A<1>		// { dg-error "deleted|context" }
+{
+  B() {}			// { dg-error "context" }
+};