This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Why GCC prefers global size-unaware deallocation function?
- From: Ruslan Garipov <brigadir15 at gmail dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Sun, 4 Dec 2016 17:26:07 +0500
- Subject: Why GCC prefers global size-unaware deallocation function?
- Authentication-results: sourceware.org; auth=none
I have the following `operator delete` replacements:
void operator delete[](void* p)
{
/* Implementation does not matter. */
}
void operator delete[](void* p, std::size_t size)
{
/* Implementation does not matter. */
}
My question is why, in the following code, GCC 6.2 calls `void
operator delete[](void*)` and not the second replacement:
char* str = new char[14];
delete[] str;
According to 5.3.5 Delete [expr.delete]:
> (10.3) If the type is complete and if, for the second alternative (delete array) only, the operand is a pointer to a class type with a non-trivial destructor or a (possibly multi-dimensional) array thereof, the function with a parameter of type std::size_t is selected.
Therefore, I believe `operator delete[](void*, std::size_t)` must be
called, doesn't it?
Thanks.