https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92023

--- Comment #2 from Bruno De Fraine <bruno-gcc at defraine dot net> ---
Thanks Richard, for explaining that gcc is optimizing the comparison between
the address of a static object and a pointer to dynamic memory returned by
operator new[]. I realized something was special about my operator delete[],
but I had not figured out what.

I cannot judge if the optimization performed by gcc is allowed by the C++
language or not, but I can certainly see how it is likely a very useful
optimization in the overwhelming majority of cases. In such a context, I can
sympathize with compilers that require that you take special care when
implementing library functions for which the compiler has built-in knowledge
(e.g. avoiding that the compiler optimizes your memcpy implementation to a
memcpy call comes to mind as a similar problem).

To avoid the optimization in my case, it seems to work to cast the pointers to
uintptr_t before comparison.

Reply via email to