From 8e8e7af514344588ff3e3da25c0cb74c12dc6a0d Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Fri, 2 Aug 2019 08:07:15 +0200 Subject: [PATCH] Mark DECL_SET_IS_OPERATOR_DELETE for user-provided delete operators. 2019-08-02 Martin Liska * decl.c (grok_op_properties): Mark DECL_SET_IS_OPERATOR_DELETE for user-provided delete operators. 2019-08-02 Martin Liska * g++.dg/cpp1y/new2.C: New test. From-SVN: r273996 --- gcc/cp/ChangeLog | 5 ++++ gcc/cp/decl.c | 5 +++- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/g++.dg/cpp1y/new2.C | 39 +++++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp1y/new2.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 02992ae9b47..b7183ac4c05 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2019-08-02 Martin Liska + + * decl.c (grok_op_properties): + Mark DECL_SET_IS_OPERATOR_DELETE for user-provided delete operators. + 2019-08-01 Martin Sebor PR c++/90947 diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index a1ab5ca8193..e0102c0067d 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -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); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6aae2e47ca5..72e258b3506 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2019-08-02 Martin Liska + + * g++.dg/cpp1y/new2.C: New test. + 2019-08-02 Senthil Kumar Selvaraj * 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 index 00000000000..926e7960528 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/new2.C @@ -0,0 +1,39 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -std=c++17 -fdump-tree-cddce-details" } */ + +#include +#include +#include + +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"} } */