Skip to content

Commit

Permalink
Mark DECL_SET_IS_OPERATOR_DELETE for user-provided delete operators.
Browse files Browse the repository at this point in the history
2019-08-02  Martin Liska  <[email protected]>

	* decl.c (grok_op_properties):
	Mark DECL_SET_IS_OPERATOR_DELETE for user-provided delete operators.
2019-08-02  Martin Liska  <[email protected]>

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

From-SVN: r273996
  • Loading branch information
marxin authored and Martin Liska committed Aug 2, 2019
1 parent 5bae71d commit 8e8e7af
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 1 deletion.
5 changes: 5 additions & 0 deletions gcc/cp/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2019-08-02 Martin Liska <[email protected]>

* decl.c (grok_op_properties):
Mark DECL_SET_IS_OPERATOR_DELETE for user-provided delete operators.

2019-08-01 Martin Sebor <[email protected]>

PR c++/90947
Expand Down
5 changes: 4 additions & 1 deletion gcc/cp/decl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions gcc/testsuite/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2019-08-02 Martin Liska <[email protected]>

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

2019-08-02 Senthil Kumar Selvaraj <[email protected]>

* gcc.dg/torture/ssa-fre-6.c: Add dg-require-effective-target int32.
Expand Down
39 changes: 39 additions & 0 deletions gcc/testsuite/g++.dg/cpp1y/new2.C
Original file line number Diff line number Diff line change
@@ -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"} } */

0 comments on commit 8e8e7af

Please sign in to comment.