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

Keith Halligan <keith.halligan at microfocus dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|INVALID                     |---

--- Comment #11 from Keith Halligan <keith.halligan at microfocus dot com> ---

I am re-opening this issue as there seems to be a bug with the 32-bit code
generation that I'm after noticing.  

While adding noexcept to the "opeator new[]()" overloaded functions does stop
the crash on 64-bit, it does nothing for the 32-bit code, with the compiler
attempting to throw a std::bad_alloc.

Below is a version of Jonathan Wakeley's modified testcase that has noexcept on
the "operator new[]()".  

$ cat bug99845.cpp && g++ -m32 -O1 -o bug99845 bug99845.cpp

namespace std {
  using size_t = decltype(sizeof(0));

  struct nothrow_t { } const nothrow = { };
}

void* operator new(std::size_t);
void* operator new[](std::size_t);
void operator delete(void*) noexcept;
void operator delete[](void*) noexcept;
void operator delete(void*, std::size_t) noexcept;
void operator delete[](void*, std::size_t) noexcept;

void* operator new(std::size_t, const std::nothrow_t&) noexcept;
void* operator new[](std::size_t, const std::nothrow_t&) noexcept;
void operator delete(void*, const std::nothrow_t&) noexcept;
void operator delete[](void*, const std::nothrow_t&) noexcept;

extern "C" int printf(const char* ...);

using std::size_t;

struct X
{
  void* operator new[](size_t sz, const std::nothrow_t& nt) noexcept {
    return ::operator new(sz, nt);
  }

  unsigned data = 0;
};

struct Y
{
  static X* alloc(unsigned n) { return new(std::nothrow) X[n]; }
};

int main()
{
  Y::alloc(-1u);
}

==
$ ./bug99845
terminate called after throwing an instance of 'std::bad_array_new_length'
  what():  std::bad_array_new_length
Aborted (core dumped)

Reply via email to