PR c++/57082 - new X{} and private destructor.
authorJason Merrill <jason@redhat.com>
Wed, 11 Dec 2019 16:51:09 +0000 (11:51 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Wed, 11 Dec 2019 16:51:09 +0000 (11:51 -0500)
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.

* init.c (build_new_1): Also pass tf_no_cleanup to
build_special_member_call.

From-SVN: r279236

gcc/cp/ChangeLog
gcc/cp/init.c
gcc/testsuite/g++.dg/cpp0x/initlist-new2.C [new file with mode: 0644]

index 6daee41c5d18efeae1b4680399498cace668bb9d..e371a408c488d1d2bfc7efd09bbe974bf4e63ef6 100644 (file)
@@ -1,5 +1,9 @@
 2019-12-11  Jason Merrill  <jason@redhat.com>
 
+       PR c++/57082 - new X{} and private destructor.
+       * init.c (build_new_1): Also pass tf_no_cleanup to
+       build_special_member_call.
+
        PR c++/92774 - ICE with implicitly deleted operator<=>.
        * method.c (comp_info::~comp_info): Factor out of...
        (build_comparison_op): Here.  Handle error return from build_new_op.
index e40afe27e1a2909e9b8a6903a582e1167b25b28e..ecd09510adb6d253d66fcc6745028887e662e65b 100644 (file)
@@ -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 (file)
index 0000000..d873138
--- /dev/null
@@ -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
+}