This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH for new with deleted delete
- From: Jason Merrill <jason at redhat dot com>
- To: gcc-patches List <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 24 Jul 2009 23:57:01 -0400
- Subject: C++ PATCH for new with deleted delete
In Frankfurt the core group decided to allow new of a class with a
deleted operator delete; it just means that the memory won't be freed if
the initialization throws.
Tested x86_64-pc-linux-gnu, applied to trunk.
2009-07-24 Jason Merrill <jason@redhat.com>
Core issue 901
* gcc/cp/call.c (build_op_delete_call): If this is for a
new-expression and the op delete is deleted, do nothing.
* libstdc++-v3/libsupc++/vec.cc (__cxa_vec_new2, __cxa_vec_new3):
Handle NULL dealloc.
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index d396aff..0254ecb 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -4595,6 +4595,10 @@ build_op_delete_call (enum tree_code code, tree addr, tree size,
if (DECL_CLASS_SCOPE_P (fn))
perform_or_defer_access_check (TYPE_BINFO (type), fn, fn);
+ /* Core issue 901: It's ok to new a type with deleted delete. */
+ if (DECL_DELETED_FN (fn) && alloc_fn)
+ return NULL_TREE;
+
if (placement)
{
/* The placement args might not be suitable for overload
diff --git a/gcc/testsuite/g++.dg/cpp0x/defaulted11.C b/gcc/testsuite/g++.dg/cpp0x/defaulted11.C
new file mode 100644
index 0000000..b9bed7e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/defaulted11.C
@@ -0,0 +1,15 @@
+// Core issue 901
+// { dg-options "-std=c++0x" }
+
+struct A
+{
+ A(); ~A();
+ void operator delete (void *) = delete;
+ void operator delete[] (void *) = delete;
+};
+
+int main()
+{
+ A* ap = new A;
+ ap = new A[2];
+}
diff --git a/libstdc++-v3/libsupc++/vec.cc b/libstdc++-v3/libsupc++/vec.cc
index f132289..e44a023 100644
--- a/libstdc++-v3/libsupc++/vec.cc
+++ b/libstdc++-v3/libsupc++/vec.cc
@@ -104,7 +104,10 @@ namespace __cxxabiv1
{
{
uncatch_exception ue;
- dealloc(base - padding_size);
+ // Core issue 901 will probably be resolved such that a
+ // deleted operator delete means not freeing memory here.
+ if (dealloc)
+ dealloc(base - padding_size);
}
__throw_exception_again;
}
@@ -142,7 +145,8 @@ namespace __cxxabiv1
{
{
uncatch_exception ue;
- dealloc(base - padding_size, size);
+ if (dealloc)
+ dealloc(base - padding_size, size);
}
__throw_exception_again;
}