Hi!

The earlier cases in build_new_1 already use | tf_no_cleanup, these are
cases where the type isn't type_build_ctor_call nor explicit_value_init_p.
It is true that often one can't delete these (unless e.g. the dtor would be
private or protected and deletion done in some method), but diagnosing that
belongs to delete, not new.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk?

2020-12-08  Jakub Jelinek  <ja...@redhat.com>

        PR c++/59238
        * init.c (build_new_1): Pass complain | tf_no_cleanup to digest_init,
        build_x_compound_expr_from_vec and cp_build_modify_expr.

        * g++.dg/cpp0x/new4.C: New test.

--- gcc/cp/init.c.jj    2020-11-19 20:08:22.831676932 +0100
+++ gcc/cp/init.c       2020-12-07 12:50:04.990586139 +0100
@@ -3485,13 +3485,14 @@ build_new_1 (vec<tree, va_gc> **placemen
                  ie = build_constructor_from_vec (init_list_type_node, *init);
                  CONSTRUCTOR_IS_DIRECT_INIT (ie) = true;
                  CONSTRUCTOR_IS_PAREN_INIT (ie) = true;
-                 ie = digest_init (type, ie, complain);
+                 ie = digest_init (type, ie, complain | tf_no_cleanup);
                }
              else
                ie = build_x_compound_expr_from_vec (*init, "new initializer",
-                                                    complain);
+                                                    complain | tf_no_cleanup);
              init_expr = cp_build_modify_expr (input_location, init_expr,
-                                               INIT_EXPR, ie, complain);
+                                               INIT_EXPR, ie,
+                                               complain | tf_no_cleanup);
            }
          /* If the initializer uses C++14 aggregate NSDMI that refer to the
             object being initialized, replace them now and don't try to
--- gcc/testsuite/g++.dg/cpp0x/new4.C.jj        2020-12-07 12:54:00.369948493 
+0100
+++ gcc/testsuite/g++.dg/cpp0x/new4.C   2020-12-07 12:53:25.917334573 +0100
@@ -0,0 +1,35 @@
+// PR c++/59238
+// { dg-do compile { target c++11 } }
+
+struct A { ~A () = delete; };
+A *pa{new A{}};
+
+class B { ~B () = default; };
+B *pb{new B{}};
+
+struct E {
+  ~E () = delete; 
+private: 
+  int x;
+};
+E *pe{new E{}};
+
+class C { ~C (); };
+C *pc{new C{}};
+
+class D { ~D () {} };
+D *pd{new D{}};
+
+struct F {
+  F () = default;
+  ~F () = delete; 
+};
+F *pf{new F{}};
+
+struct G {
+  G () = default;
+  ~G () = delete; 
+private: 
+  int x;
+};
+G *pg{new G{}};

        Jakub

Reply via email to