[question] сpp-test: own global delete operator

Hi all!

There is the cpp-test “p755a.cpp”:

// It checks to see if you can define your own global delete operator.
extern “C” void _exit(int);
void operator delete(void p) throw() {
_exit(0);
}
int main () {
int
i = new int;
delete i;
return 1;
}

clang-3.8 returns 0 with O0 and returns 1 with O1
gcc always returns 0

clang with O1 uses default “delete”:

clang-3.8 -c -S p755a.cpp -O1


main: # @main
.cfi_startproc

BB#0: # %entry

movl $1, %eax
retq
.Lfunc_end1:
.size main, .Lfunc_end1-main
.cfi_endproc

As far as I understand it is not right…

I will be grateful to get any explanations.

PS
I haven’t tested clang 4.0 yet…

C++ compilers are allowed to delete paired new/delete expressions after N3664, which I believe was voted into C++14. If you do not want this behavior, call ‘::operator new/delete’ instead.

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3664.html