Mark DECL_SET_IS_OPERATOR_DELETE for user-provided delete operators.
authorMartin Liska <mliska@suse.cz>
Fri, 2 Aug 2019 06:07:15 +0000 (08:07 +0200)
committerMartin Liska <marxin@gcc.gnu.org>
Fri, 2 Aug 2019 06:07:15 +0000 (06:07 +0000)
2019-08-02  Martin Liska  <mliska@suse.cz>

* decl.c (grok_op_properties):
Mark DECL_SET_IS_OPERATOR_DELETE for user-provided delete operators.
2019-08-02  Martin Liska  <mliska@suse.cz>

* g++.dg/cpp1y/new2.C: New test.

From-SVN: r273996

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp1y/new2.C [new file with mode: 0644]

index 02992ae9b470112bfc87a1e733aba9cd1421210b..b7183ac4c05cca2f972decf23f45983d3e60eceb 100644 (file)
@@ -1,3 +1,8 @@
+2019-08-02  Martin Liska  <mliska@suse.cz>
+
+       * decl.c (grok_op_properties):
+       Mark DECL_SET_IS_OPERATOR_DELETE for user-provided delete operators.
+
 2019-08-01  Martin Sebor  <msebor@redhat.com>
 
        PR c++/90947
index a1ab5ca81933118622f5dccfcd737ed22369b297..e0102c0067dc96d167b528c086692e3f2313176b 100644 (file)
@@ -13678,7 +13678,10 @@ grok_op_properties (tree decl, bool complain)
        }
 
       if (op_flags & OVL_OP_FLAG_DELETE)
-       coerce_delete_type (decl, loc);
+       {
+         DECL_SET_IS_OPERATOR_DELETE (decl, true);
+         coerce_delete_type (decl, loc);
+       }
       else
        {
          DECL_SET_IS_OPERATOR_NEW (decl, true);
index 6aae2e47ca56bfa4901d2f3b68b4dfef861a47f1..72e258b3506735d0c14f335df9dcc27b54bf3e13 100644 (file)
@@ -1,3 +1,7 @@
+2019-08-02  Martin Liska  <mliska@suse.cz>
+
+       * g++.dg/cpp1y/new2.C: New test.
+
 2019-08-02  Senthil Kumar Selvaraj  <senthilkumar.selvaraj@microchip.com>
 
        * gcc.dg/torture/ssa-fre-6.c: Add dg-require-effective-target int32.
diff --git a/gcc/testsuite/g++.dg/cpp1y/new2.C b/gcc/testsuite/g++.dg/cpp1y/new2.C
new file mode 100644 (file)
index 0000000..926e796
--- /dev/null
@@ -0,0 +1,39 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -std=c++17 -fdump-tree-cddce-details" } */
+
+#include <cstdio>
+#include <cstdlib>
+#include <new>
+
+void* operator new(std::size_t sz)
+{
+  std::printf("global op new called, size = %zu\n", sz);
+  void *ptr = std::malloc(sz);
+  if (ptr)
+    return ptr;
+  else
+    throw std::bad_alloc{};
+}
+
+void operator delete(void* ptr) noexcept
+{
+  std::puts("global op delete called");
+  std::free(ptr);
+}
+
+void
+new_primitive_load() {
+  int *x = new int;
+  int tmp = *x;
+  delete x;
+}
+
+void
+new_array_load() {
+  int *x = new int[10];
+  int tmp = x[4];
+  delete [] x;
+}
+
+/* { dg-final { scan-tree-dump-times "Deleting : _\\d+ = operator new" 2 "cddce1"} } */
+/* { dg-final { scan-tree-dump-times "Deleting : operator delete" 2 "cddce1"} } */