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

Reid Kleckner via llvm-dev llvm-dev at lists.llvm.org
Thu Mar 30 11:09:16 PDT 2017


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

On Thu, Mar 30, 2017 at 9:51 AM, Daniil Troshkov via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> 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...
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170330/9eaa1b80/attachment.html>


More information about the llvm-dev mailing list