[libcxx-commits] [PATCH] D110846: [libcxx] Make allocator<T>:allocate throw bad_array_new_length

Arthur O'Dwyer via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Oct 4 10:29:56 PDT 2021


Quuxplusone added inline comments.


================
Comment at: libcxx/include/new:151
 _LIBCPP_NORETURN _LIBCPP_FUNC_VIS void __throw_bad_alloc();  // not in C++ spec
+_LIBCPP_NORETURN _LIBCPP_FUNC_VIS void __libcpp_throw_bad_array_new_length();
 
----------------
ldionne wrote:
> miyuki wrote:
> > miyuki wrote:
> > > ldionne wrote:
> > > > For consistency?
> > > The function `__throw_bad_array_new_length` is implemented in libstdc++, so it doesn't get defined when using libsupc++ as the ABI library. There is no `__throw_bad_array_new_length function` in libstdc++, but I thought that this might change in the future, so I named the function differently to avoid possible name clash.
> > > 
> > > But now I noticed that there is a `__cxa_throw_bad_array_new_length` function which is part of the Itanium ABI and is implemented in both libc++abi and libsupc++ (introduced in CXXABI_1.3.8, GCC 4.9). Should I use it instead?
> > I meant to say "The function `__throw_bad_alloc `is implemented in libstdc++"
> The issue I see with using `__cxa_throw_bad_array_new_length` is the same as with defining `__libcpp_throw_bad_array_new_length` in the dylib -- a program deployed against an OS where the `libc++.dylib` (well, `libc++abi.dylib` really) doesn't ship that symbol would fail to run.
`__cxa_throw_bad_array_new_length` //is// part of the Itanium C++ ABI, so it should be available on most systems... but yeah, perhaps it wouldn't be there on Windows. And also, looking at `git grep __cxa_ libcxx/`, we can see that libc++ generally doesn't contain calls to `__cxa_` functions, so there's no reason to start now.
I think an inline `__throw_bad_array_new_length` [no `_libcpp_`] defined in the header sounds like the most conventional, and thus best, answer.


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

https://reviews.llvm.org/D110846



More information about the libcxx-commits mailing list