[C++ PATCH] PR c++/57082 - new X{} and private destructor.

Jason Merrill jason@redhat.com
Wed Dec 11 16:50:00 GMT 2019


build_new_1 already passes tf_no_cleanup to build_value_init, but in this
testcase we end up calling build_value_init by way of
build_special_member_call, so we need to pass it to that function as well.

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

	* init.c (build_new_1): Also pass tf_no_cleanup to
	build_special_member_call.
---
 gcc/cp/init.c                              |  2 +-
 gcc/testsuite/g++.dg/cpp0x/initlist-new2.C | 15 +++++++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp0x/initlist-new2.C

diff --git a/gcc/cp/init.c b/gcc/cp/init.c
index e40afe27e1a..ecd09510adb 100644
--- a/gcc/cp/init.c
+++ b/gcc/cp/init.c
@@ -3591,7 +3591,7 @@ build_new_1 (vec<tree, va_gc> **placement, tree type, tree nelts,
 						     complete_ctor_identifier,
 						     init, elt_type,
 						     LOOKUP_NORMAL,
-                                                     complain);
+						     complain|tf_no_cleanup);
 	    }
 	  else if (explicit_value_init_p)
 	    {
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist-new2.C b/gcc/testsuite/g++.dg/cpp0x/initlist-new2.C
new file mode 100644
index 00000000000..d8731389a65
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/initlist-new2.C
@@ -0,0 +1,15 @@
+// PR c++/57082
+// { dg-do compile { target c++11 } }
+
+struct X
+{
+private:
+  ~X() {}
+};
+
+int main()
+{
+  new X;    // OK
+  new X();  // OK
+  new X{};  // ERROR
+}

base-commit: 945f2b19497eff52ef44923d291bf0fdba043299
-- 
2.18.1



More information about the Gcc-patches mailing list