diff --git a/libcxx/src/CMakeLists.txt b/libcxx/src/CMakeLists.txt --- a/libcxx/src/CMakeLists.txt +++ b/libcxx/src/CMakeLists.txt @@ -36,6 +36,7 @@ mutex_destructor.cpp new.cpp new_handler.cpp + new_helpers.cpp optional.cpp random_shuffle.cpp ryu/d2fixed.cpp diff --git a/libcxx/src/new.cpp b/libcxx/src/new.cpp --- a/libcxx/src/new.cpp +++ b/libcxx/src/new.cpp @@ -10,29 +10,6 @@ #include #include -namespace std -{ - -#ifndef __GLIBCXX__ -const nothrow_t nothrow{}; -#endif - -#ifndef LIBSTDCXX - -void -__throw_bad_alloc() -{ -#ifndef _LIBCPP_HAS_NO_EXCEPTIONS - throw bad_alloc(); -#else - _VSTD::abort(); -#endif -} - -#endif // !LIBSTDCXX - -} // std - #if !defined(__GLIBCXX__) && \ !defined(_LIBCPP_ABI_VCRUNTIME) && \ !defined(_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS) diff --git a/libcxx/src/new_helpers.cpp b/libcxx/src/new_helpers.cpp new file mode 100644 --- /dev/null +++ b/libcxx/src/new_helpers.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include +#include + +namespace std { // purposefully not versioned + +#ifndef __GLIBCXX__ +const nothrow_t nothrow{}; +#endif + +#ifndef LIBSTDCXX + +void __throw_bad_alloc() { +# ifndef _LIBCPP_HAS_NO_EXCEPTIONS + throw bad_alloc(); +# else + _VSTD::abort(); +# endif +} + +#endif // !LIBSTDCXX + +} // namespace std