[libcxx-commits] [PATCH] D150610: [libc++] Make sure `operator new` never returns nullptr, even under -fno-exceptions

Paul Robinson via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Jun 13 10:47:21 PDT 2023


probinson added a comment.

> The Standard has a few requirements for the allocation functions, some of which are impossible to satisfy under -fno-exceptions:
>
> 1. operator new(size_t) must never return nullptr
> 2. operator new(size_t, nothrow_t) must call the throwing version and return nullptr on failure to allocate
> 3. We can't throw exceptions when compiled with -fno-exceptions

Feels like building the library with `-fno-exceptions` is just plain non-conforming?

Requirement 2 seems odd, the only justification I can come up with is to allow replacing _only_ the throwing version, and having the nothrow version still Just Work in a compatible way. Naively I'd have thought the other way around would make more sense (throwing version calls nothrow version and turns nullptr into throw/abort) but that's not what got standardized.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150610/new/

https://reviews.llvm.org/D150610



More information about the libcxx-commits mailing list