https://bugs.llvm.org/show_bug.cgi?id=42564

            Bug ID: 42564
           Summary: calls to operator delete(..., const std::nothrow_t &)
                    are optimized out
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangb...@nondot.org
          Reporter: m...@trust-in-soft.com
                CC: blitzrak...@gmail.com, dgre...@apple.com,
                    erik.pilking...@gmail.com, llvm-bugs@lists.llvm.org,
                    richard-l...@metafoo.co.uk

Created attachment 22220
  --> https://bugs.llvm.org/attachment.cgi?id=22220&action=edit
simple testcase

When a nothrow placement new flavour is used to allocate and initialize an
object, and the object's constructor throws an exception, the matching nothrow
delete operator must be invoked.

However, as soon as optimization is turned on, calls to these operators are
removed.

Consider the following trivial code:

#include <cstdio>
#include <new>

void operator delete(void *, const std::nothrow_t &) noexcept { printf("delete
nothrow\n"); }
void operator delete[](void *, const std::nothrow_t &) noexcept {
printf("delete[] nothrow\n"); }

struct A { A() { throw 42; } };

int
main(int argc, char *argv[])
{
    try { A *a = new(std::nothrow) A; } catch (...) { }
    try { A *arr = new(std::nothrow) A[2]; } catch (...) { }
}


$ clang++ -O0 -fexceptions test.cpp && ./a.out
delete nothrow
delete[] nothrow
$ clang++ -O2 -fexceptions test.cpp && ./a.out
$

Tested with 7.0, 8.0 and today's godbolts' trunk on linux/x86_64.

FWIW, g++ -O0 and -O2 compile this correctly (with the operators being
invoked).

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to