[libc++] Granularize the <new> header (#119270)

This disentangles the code which previously had a mix of many #ifdefs, a
non-versioned namespace and a versioned namespace. It also makes it
clearer which parts of <new> are implemented on Windows by including <new.h>.
This commit is contained in:
Louis Dionne 2024-12-13 14:17:56 -05:00 committed by GitHub
parent d1f51c67fd
commit 9474e09459
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
35 changed files with 556 additions and 302 deletions

View File

@ -581,6 +581,16 @@ set(files
__mutex/once_flag.h
__mutex/tag_types.h
__mutex/unique_lock.h
__new/align_val_t.h
__new/allocate.h
__new/destroying_delete_t.h
__new/exceptions.h
__new/global_new_delete.h
__new/interference_size.h
__new/launder.h
__new/new_handler.h
__new/nothrow_t.h
__new/placement_new_delete.h
__node_handle
__numeric/accumulate.h
__numeric/adjacent_difference.h

View File

@ -26,6 +26,7 @@
#include <__memory/pointer_traits.h>
#include <__memory/swap_allocator.h>
#include <__memory/unique_ptr.h>
#include <__new/launder.h>
#include <__type_traits/can_extract_key.h>
#include <__type_traits/conditional.h>
#include <__type_traits/enable_if.h>
@ -46,7 +47,6 @@
#include <__utility/swap.h>
#include <cstring>
#include <limits>
#include <new> // __launder
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header

View File

@ -12,6 +12,7 @@
#include <__config>
#include <__cstddef/ptrdiff_t.h>
#include <__cstddef/size_t.h>
#include <__memory/addressof.h>
#include <__memory/allocate_at_least.h>
#include <__memory/allocator_traits.h>

View File

@ -10,6 +10,7 @@
#define _LIBCPP___MEMORY_BUILTIN_NEW_ALLOCATOR_H
#include <__config>
#include <__cstddef/size_t.h>
#include <__memory/unique_ptr.h>
#include <new>

View File

@ -14,12 +14,12 @@
#include <__config>
#include <__iterator/access.h>
#include <__memory/addressof.h>
#include <__new/placement_new_delete.h>
#include <__type_traits/enable_if.h>
#include <__type_traits/is_array.h>
#include <__utility/declval.h>
#include <__utility/forward.h>
#include <__utility/move.h>
#include <new>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header

View File

@ -43,6 +43,7 @@
#include <__type_traits/is_bounded_array.h>
#include <__type_traits/is_constructible.h>
#include <__type_traits/is_convertible.h>
#include <__type_traits/is_function.h>
#include <__type_traits/is_reference.h>
#include <__type_traits/is_same.h>
#include <__type_traits/is_unbounded_array.h>

View File

@ -15,6 +15,7 @@
#include <__algorithm/unwrap_iter.h>
#include <__algorithm/unwrap_range.h>
#include <__config>
#include <__cstddef/size_t.h>
#include <__iterator/iterator_traits.h>
#include <__iterator/reverse_iterator.h>
#include <__memory/addressof.h>

View File

@ -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
//
//===----------------------------------------------------------------------===//
#ifndef _LIBCPP___NEW_ALIGN_VAL_T_H
#define _LIBCPP___NEW_ALIGN_VAL_T_H
#include <__config>
#include <__cstddef/size_t.h>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif
// purposefully not using versioning namespace
namespace std {
#if _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION && !defined(_LIBCPP_ABI_VCRUNTIME)
# ifndef _LIBCPP_CXX03_LANG
enum class align_val_t : size_t {};
# else
enum align_val_t { __zero = 0, __max = (size_t)-1 };
# endif
#endif
} // namespace std
#endif // _LIBCPP___NEW_ALIGN_VAL_T_H

View File

@ -0,0 +1,101 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
#ifndef _LIBCPP___NEW_ALLOCATE_H
#define _LIBCPP___NEW_ALLOCATE_H
#include <__config>
#include <__cstddef/max_align_t.h>
#include <__cstddef/size_t.h>
#include <__new/align_val_t.h>
#include <__new/global_new_delete.h> // for _LIBCPP_HAS_SIZED_DEALLOCATION
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
_LIBCPP_CONSTEXPR inline _LIBCPP_HIDE_FROM_ABI bool __is_overaligned_for_new(size_t __align) _NOEXCEPT {
#ifdef __STDCPP_DEFAULT_NEW_ALIGNMENT__
return __align > __STDCPP_DEFAULT_NEW_ALIGNMENT__;
#else
return __align > _LIBCPP_ALIGNOF(max_align_t);
#endif
}
template <class... _Args>
_LIBCPP_HIDE_FROM_ABI void* __libcpp_operator_new(_Args... __args) {
#if __has_builtin(__builtin_operator_new) && __has_builtin(__builtin_operator_delete)
return __builtin_operator_new(__args...);
#else
return ::operator new(__args...);
#endif
}
template <class... _Args>
_LIBCPP_HIDE_FROM_ABI void __libcpp_operator_delete(_Args... __args) _NOEXCEPT {
#if __has_builtin(__builtin_operator_new) && __has_builtin(__builtin_operator_delete)
__builtin_operator_delete(__args...);
#else
::operator delete(__args...);
#endif
}
inline _LIBCPP_HIDE_FROM_ABI void* __libcpp_allocate(size_t __size, size_t __align) {
#if _LIBCPP_HAS_ALIGNED_ALLOCATION
if (__is_overaligned_for_new(__align)) {
const align_val_t __align_val = static_cast<align_val_t>(__align);
return __libcpp_operator_new(__size, __align_val);
}
#endif
(void)__align;
return __libcpp_operator_new(__size);
}
template <class... _Args>
_LIBCPP_HIDE_FROM_ABI void __do_deallocate_handle_size(void* __ptr, size_t __size, _Args... __args) _NOEXCEPT {
#if !_LIBCPP_HAS_SIZED_DEALLOCATION
(void)__size;
return std::__libcpp_operator_delete(__ptr, __args...);
#else
return std::__libcpp_operator_delete(__ptr, __size, __args...);
#endif
}
inline _LIBCPP_HIDE_FROM_ABI void __libcpp_deallocate(void* __ptr, size_t __size, size_t __align) _NOEXCEPT {
#if !_LIBCPP_HAS_ALIGNED_ALLOCATION
(void)__align;
return __do_deallocate_handle_size(__ptr, __size);
#else
if (__is_overaligned_for_new(__align)) {
const align_val_t __align_val = static_cast<align_val_t>(__align);
return __do_deallocate_handle_size(__ptr, __size, __align_val);
} else {
return __do_deallocate_handle_size(__ptr, __size);
}
#endif
}
inline _LIBCPP_HIDE_FROM_ABI void __libcpp_deallocate_unsized(void* __ptr, size_t __align) _NOEXCEPT {
#if !_LIBCPP_HAS_ALIGNED_ALLOCATION
(void)__align;
return __libcpp_operator_delete(__ptr);
#else
if (__is_overaligned_for_new(__align)) {
const align_val_t __align_val = static_cast<align_val_t>(__align);
return __libcpp_operator_delete(__ptr, __align_val);
} else {
return __libcpp_operator_delete(__ptr);
}
#endif
}
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP___NEW_ALLOCATE_H

View File

@ -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
//
//===----------------------------------------------------------------------===//
#ifndef _LIBCPP___NEW_DESTROYING_DELETE_T_H
#define _LIBCPP___NEW_DESTROYING_DELETE_T_H
#include <__config>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif
#if _LIBCPP_STD_VER >= 20
// purposefully not using versioning namespace
namespace std {
// Enable the declaration even if the compiler doesn't support the language
// feature.
struct destroying_delete_t {
explicit destroying_delete_t() = default;
};
inline constexpr destroying_delete_t destroying_delete{};
} // namespace std
#endif
#endif // _LIBCPP___NEW_DESTROYING_DELETE_T_H

View File

@ -0,0 +1,74 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
#ifndef _LIBCPP___NEW_EXCEPTIONS_H
#define _LIBCPP___NEW_EXCEPTIONS_H
#include <__config>
#include <__exception/exception.h>
#include <__verbose_abort>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif
// purposefully not using versioning namespace
namespace std {
#if !defined(_LIBCPP_ABI_VCRUNTIME)
class _LIBCPP_EXPORTED_FROM_ABI bad_alloc : public exception {
public:
bad_alloc() _NOEXCEPT;
_LIBCPP_HIDE_FROM_ABI bad_alloc(const bad_alloc&) _NOEXCEPT = default;
_LIBCPP_HIDE_FROM_ABI bad_alloc& operator=(const bad_alloc&) _NOEXCEPT = default;
~bad_alloc() _NOEXCEPT override;
const char* what() const _NOEXCEPT override;
};
class _LIBCPP_EXPORTED_FROM_ABI bad_array_new_length : public bad_alloc {
public:
bad_array_new_length() _NOEXCEPT;
_LIBCPP_HIDE_FROM_ABI bad_array_new_length(const bad_array_new_length&) _NOEXCEPT = default;
_LIBCPP_HIDE_FROM_ABI bad_array_new_length& operator=(const bad_array_new_length&) _NOEXCEPT = default;
~bad_array_new_length() _NOEXCEPT override;
const char* what() const _NOEXCEPT override;
};
#elif defined(_HAS_EXCEPTIONS) && _HAS_EXCEPTIONS == 0 // !_LIBCPP_ABI_VCRUNTIME
// When _HAS_EXCEPTIONS == 0, these complete definitions are needed,
// since they would normally be provided in vcruntime_exception.h
class bad_alloc : public exception {
public:
bad_alloc() noexcept : exception("bad allocation") {}
private:
friend class bad_array_new_length;
bad_alloc(char const* const __message) noexcept : exception(__message) {}
};
class bad_array_new_length : public bad_alloc {
public:
bad_array_new_length() noexcept : bad_alloc("bad array new length") {}
};
#endif // defined(_LIBCPP_ABI_VCRUNTIME) && defined(_HAS_EXCEPTIONS) && _HAS_EXCEPTIONS == 0
[[__noreturn__]] _LIBCPP_EXPORTED_FROM_ABI void __throw_bad_alloc(); // not in C++ spec
[[__noreturn__]] inline _LIBCPP_HIDE_FROM_ABI void __throw_bad_array_new_length() {
#if _LIBCPP_HAS_EXCEPTIONS
throw bad_array_new_length();
#else
_LIBCPP_VERBOSE_ABORT("bad_array_new_length was thrown in -fno-exceptions mode");
#endif
}
} // namespace std
#endif // _LIBCPP___NEW_EXCEPTIONS_H

View File

@ -0,0 +1,89 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
#ifndef _LIBCPP___NEW_GLOBAL_NEW_DELETE_H
#define _LIBCPP___NEW_GLOBAL_NEW_DELETE_H
#include <__config>
#include <__cstddef/size_t.h>
#include <__new/align_val_t.h>
#include <__new/exceptions.h>
#include <__new/nothrow_t.h>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif
#if defined(_LIBCPP_CXX03_LANG)
# define _THROW_BAD_ALLOC throw(std::bad_alloc)
#else
# define _THROW_BAD_ALLOC
#endif
#if defined(__cpp_sized_deallocation) && __cpp_sized_deallocation >= 201309L
# define _LIBCPP_HAS_LANGUAGE_SIZED_DEALLOCATION 1
#else
# define _LIBCPP_HAS_LANGUAGE_SIZED_DEALLOCATION 0
#endif
#if _LIBCPP_STD_VER >= 14 || _LIBCPP_HAS_LANGUAGE_SIZED_DEALLOCATION
# define _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION 1
#else
# define _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION 0
#endif
#if _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION && _LIBCPP_HAS_LANGUAGE_SIZED_DEALLOCATION
# define _LIBCPP_HAS_SIZED_DEALLOCATION 1
#else
# define _LIBCPP_HAS_SIZED_DEALLOCATION 0
#endif
#if defined(_LIBCPP_ABI_VCRUNTIME)
# include <new.h>
#else
[[__nodiscard__]] _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz) _THROW_BAD_ALLOC;
[[__nodiscard__]] _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, const std::nothrow_t&) _NOEXCEPT
_LIBCPP_NOALIAS;
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p) _NOEXCEPT;
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, const std::nothrow_t&) _NOEXCEPT;
# if _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::size_t __sz) _NOEXCEPT;
# endif
[[__nodiscard__]] _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz) _THROW_BAD_ALLOC;
[[__nodiscard__]] _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz, const std::nothrow_t&) _NOEXCEPT
_LIBCPP_NOALIAS;
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p) _NOEXCEPT;
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, const std::nothrow_t&) _NOEXCEPT;
# if _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::size_t __sz) _NOEXCEPT;
# endif
# if _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION
[[__nodiscard__]] _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, std::align_val_t) _THROW_BAD_ALLOC;
[[__nodiscard__]] _LIBCPP_OVERRIDABLE_FUNC_VIS void*
operator new(std::size_t __sz, std::align_val_t, const std::nothrow_t&) _NOEXCEPT _LIBCPP_NOALIAS;
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::align_val_t) _NOEXCEPT;
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::align_val_t, const std::nothrow_t&) _NOEXCEPT;
# if _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::size_t __sz, std::align_val_t) _NOEXCEPT;
# endif
[[__nodiscard__]] _LIBCPP_OVERRIDABLE_FUNC_VIS void*
operator new[](std::size_t __sz, std::align_val_t) _THROW_BAD_ALLOC;
[[__nodiscard__]] _LIBCPP_OVERRIDABLE_FUNC_VIS void*
operator new[](std::size_t __sz, std::align_val_t, const std::nothrow_t&) _NOEXCEPT _LIBCPP_NOALIAS;
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::align_val_t) _NOEXCEPT;
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::align_val_t, const std::nothrow_t&) _NOEXCEPT;
# if _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::size_t __sz, std::align_val_t) _NOEXCEPT;
# endif
# endif
#endif
#endif // _LIBCPP___NEW_GLOBAL_NEW_DELETE_H

View File

@ -0,0 +1,34 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
#ifndef _LIBCPP___NEW_INTERFERENCE_SIZE_H
#define _LIBCPP___NEW_INTERFERENCE_SIZE_H
#include <__config>
#include <__cstddef/size_t.h>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
#if _LIBCPP_STD_VER >= 17
# if defined(__GCC_DESTRUCTIVE_SIZE) && defined(__GCC_CONSTRUCTIVE_SIZE)
inline constexpr size_t hardware_destructive_interference_size = __GCC_DESTRUCTIVE_SIZE;
inline constexpr size_t hardware_constructive_interference_size = __GCC_CONSTRUCTIVE_SIZE;
# endif // defined(__GCC_DESTRUCTIVE_SIZE) && defined(__GCC_CONSTRUCTIVE_SIZE)
#endif // _LIBCPP_STD_VER >= 17
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP___NEW_INTERFERENCE_SIZE_H

View File

@ -0,0 +1,36 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
#ifndef _LIBCPP___NEW_LAUNDER_H
#define _LIBCPP___NEW_LAUNDER_H
#include <__config>
#include <__type_traits/is_function.h>
#include <__type_traits/is_void.h>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _Tp>
[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp* __launder(_Tp* __p) _NOEXCEPT {
static_assert(!(is_function<_Tp>::value), "can't launder functions");
static_assert(!is_void<_Tp>::value, "can't launder cv-void");
return __builtin_launder(__p);
}
#if _LIBCPP_STD_VER >= 17
template <class _Tp>
[[nodiscard]] inline _LIBCPP_HIDE_FROM_ABI constexpr _Tp* launder(_Tp* __p) noexcept {
return std::__launder(__p);
}
#endif
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP___NEW_LAUNDER_H

View File

@ -0,0 +1,29 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
#ifndef _LIBCPP___NEW_NEW_HANDLER_H
#define _LIBCPP___NEW_NEW_HANDLER_H
#include <__config>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif
#if defined(_LIBCPP_ABI_VCRUNTIME)
# include <new.h>
#else
// purposefully not using versioning namespace
namespace std {
typedef void (*new_handler)();
_LIBCPP_EXPORTED_FROM_ABI new_handler set_new_handler(new_handler) _NOEXCEPT;
_LIBCPP_EXPORTED_FROM_ABI new_handler get_new_handler() _NOEXCEPT;
} // namespace std
#endif // _LIBCPP_ABI_VCRUNTIME
#endif // _LIBCPP___NEW_NEW_HANDLER_H

View File

@ -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
//
//===----------------------------------------------------------------------===//
#ifndef _LIBCPP___NEW_NOTHROW_T_H
#define _LIBCPP___NEW_NOTHROW_T_H
#include <__config>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif
#if defined(_LIBCPP_ABI_VCRUNTIME)
# include <new.h>
#else
// purposefully not using versioning namespace
namespace std {
struct _LIBCPP_EXPORTED_FROM_ABI nothrow_t {
explicit nothrow_t() = default;
};
extern _LIBCPP_EXPORTED_FROM_ABI const nothrow_t nothrow;
} // namespace std
#endif // _LIBCPP_ABI_VCRUNTIME
#endif // _LIBCPP___NEW_NOTHROW_T_H

View File

@ -0,0 +1,34 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
#ifndef _LIBCPP___NEW_PLACEMENT_NEW_DELETE_H
#define _LIBCPP___NEW_PLACEMENT_NEW_DELETE_H
#include <__config>
#include <__cstddef/size_t.h>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif
#if defined(_LIBCPP_ABI_VCRUNTIME)
# include <new.h>
#else
[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void*
operator new(std::size_t, void* __p) _NOEXCEPT {
return __p;
}
[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void*
operator new[](std::size_t, void* __p) _NOEXCEPT {
return __p;
}
inline _LIBCPP_HIDE_FROM_ABI void operator delete(void*, void*) _NOEXCEPT {}
inline _LIBCPP_HIDE_FROM_ABI void operator delete[](void*, void*) _NOEXCEPT {}
#endif
#endif // _LIBCPP___NEW_PLACEMENT_NEW_DELETE_H

View File

@ -11,6 +11,7 @@
#include <__config>
#include <__cstddef/byte.h>
#include <__cstddef/size_t.h>
#include <__memory/construct_at.h>
#include <__type_traits/decay.h>
#include <__type_traits/is_trivially_constructible.h>

View File

@ -563,6 +563,7 @@ _LIBCPP_POP_MACROS
# include <concepts>
# include <cstdlib>
# include <iterator>
# include <new>
# include <type_traits>
# include <utility>
# endif

View File

@ -112,6 +112,7 @@ _LIBCPP_END_NAMESPACE_STD
# include <cstring>
# include <iosfwd>
# include <limits>
# include <new>
# include <type_traits>
# endif
#endif // 0

View File

@ -216,6 +216,7 @@ template <class T, class Allocator, class Predicate>
# include <__memory/pointer_traits.h>
# include <__memory/swap_allocator.h>
# include <__memory_resource/polymorphic_allocator.h>
# include <__new/launder.h>
# include <__ranges/access.h>
# include <__ranges/concepts.h>
# include <__ranges/container_compatible_range.h>
@ -235,7 +236,6 @@ template <class T, class Allocator, class Predicate>
# include <__utility/move.h>
# include <__utility/swap.h>
# include <limits>
# include <new> // __launder
# include <version>
// standard-mandated includes

View File

@ -373,6 +373,7 @@ template <class R, class Alloc> struct uses_allocator<packaged_task<R>, Alloc>;
# include <__chrono/steady_clock.h>
# include <__chrono/time_point.h>
# include <__condition_variable/condition_variable.h>
# include <__cstddef/nullptr_t.h>
# include <__exception/exception_ptr.h>
# include <__memory/addressof.h>
# include <__memory/allocator.h>

View File

@ -222,6 +222,7 @@ template <class T, class Allocator, class Predicate>
# include <__memory/pointer_traits.h>
# include <__memory/swap_allocator.h>
# include <__memory_resource/polymorphic_allocator.h>
# include <__new/launder.h>
# include <__ranges/access.h>
# include <__ranges/concepts.h>
# include <__ranges/container_compatible_range.h>
@ -240,7 +241,6 @@ template <class T, class Allocator, class Predicate>
# include <__utility/swap.h>
# include <cstring>
# include <limits>
# include <new> // __launder
# include <version>
// standard-mandated includes

View File

@ -1603,6 +1603,17 @@ module std [system] {
module new {
header "new"
module align_val_t { header "__new/align_val_t.h" }
module allocate { header "__new/allocate.h" }
module destroying_delete_t { header "__new/destroying_delete_t.h" }
module exceptions { header "__new/exceptions.h" }
module global_new_delete { header "__new/global_new_delete.h" }
module interference_size { header "__new/interference_size.h" }
module launder { header "__new/launder.h" }
module new_handler { header "__new/new_handler.h" }
module nothrow_t { header "__new/nothrow_t.h" }
module placement_new_delete { header "__new/placement_new_delete.h" }
export *
}

View File

@ -89,285 +89,30 @@ void operator delete[](void* ptr, void*) noexcept;
#if 0
#else // 0
# include <__config>
# include <__cstddef/max_align_t.h>
# include <__cstddef/size_t.h>
# include <__exception/exception.h>
# include <__type_traits/is_function.h>
# include <__type_traits/is_void.h>
# include <__verbose_abort>
# include <version>
# include <__new/align_val_t.h>
# include <__new/allocate.h>
# include <__new/exceptions.h>
# include <__new/global_new_delete.h>
# include <__new/new_handler.h>
# include <__new/nothrow_t.h>
# include <__new/placement_new_delete.h>
# if defined(_LIBCPP_ABI_VCRUNTIME)
# include <new.h>
# if _LIBCPP_STD_VER >= 17
# include <__new/interference_size.h>
# include <__new/launder.h>
# endif
# if _LIBCPP_STD_VER >= 20
# include <__new/destroying_delete_t.h>
# endif
// feature-test macros
# include <version>
# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
# endif
# if defined(__cpp_sized_deallocation) && __cpp_sized_deallocation >= 201309L
# define _LIBCPP_HAS_LANGUAGE_SIZED_DEALLOCATION 1
# else
# define _LIBCPP_HAS_LANGUAGE_SIZED_DEALLOCATION 0
# endif
# if _LIBCPP_STD_VER >= 14 || _LIBCPP_HAS_LANGUAGE_SIZED_DEALLOCATION
# define _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION 1
# else
# define _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION 0
# endif
# if _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION && _LIBCPP_HAS_LANGUAGE_SIZED_DEALLOCATION
# define _LIBCPP_HAS_SIZED_DEALLOCATION 1
# else
# define _LIBCPP_HAS_SIZED_DEALLOCATION 0
# endif
namespace std // purposefully not using versioning namespace
{
# if !defined(_LIBCPP_ABI_VCRUNTIME)
struct _LIBCPP_EXPORTED_FROM_ABI nothrow_t {
explicit nothrow_t() = default;
};
extern _LIBCPP_EXPORTED_FROM_ABI const nothrow_t nothrow;
class _LIBCPP_EXPORTED_FROM_ABI bad_alloc : public exception {
public:
bad_alloc() _NOEXCEPT;
_LIBCPP_HIDE_FROM_ABI bad_alloc(const bad_alloc&) _NOEXCEPT = default;
_LIBCPP_HIDE_FROM_ABI bad_alloc& operator=(const bad_alloc&) _NOEXCEPT = default;
~bad_alloc() _NOEXCEPT override;
const char* what() const _NOEXCEPT override;
};
class _LIBCPP_EXPORTED_FROM_ABI bad_array_new_length : public bad_alloc {
public:
bad_array_new_length() _NOEXCEPT;
_LIBCPP_HIDE_FROM_ABI bad_array_new_length(const bad_array_new_length&) _NOEXCEPT = default;
_LIBCPP_HIDE_FROM_ABI bad_array_new_length& operator=(const bad_array_new_length&) _NOEXCEPT = default;
~bad_array_new_length() _NOEXCEPT override;
const char* what() const _NOEXCEPT override;
};
typedef void (*new_handler)();
_LIBCPP_EXPORTED_FROM_ABI new_handler set_new_handler(new_handler) _NOEXCEPT;
_LIBCPP_EXPORTED_FROM_ABI new_handler get_new_handler() _NOEXCEPT;
# elif defined(_HAS_EXCEPTIONS) && _HAS_EXCEPTIONS == 0 // !_LIBCPP_ABI_VCRUNTIME
// When _HAS_EXCEPTIONS == 0, these complete definitions are needed,
// since they would normally be provided in vcruntime_exception.h
class bad_alloc : public exception {
public:
bad_alloc() noexcept : exception("bad allocation") {}
private:
friend class bad_array_new_length;
bad_alloc(char const* const __message) noexcept : exception(__message) {}
};
class bad_array_new_length : public bad_alloc {
public:
bad_array_new_length() noexcept : bad_alloc("bad array new length") {}
};
# endif // defined(_LIBCPP_ABI_VCRUNTIME) && defined(_HAS_EXCEPTIONS) && _HAS_EXCEPTIONS == 0
[[__noreturn__]] _LIBCPP_EXPORTED_FROM_ABI void __throw_bad_alloc(); // not in C++ spec
[[__noreturn__]] inline _LIBCPP_HIDE_FROM_ABI void __throw_bad_array_new_length() {
# if _LIBCPP_HAS_EXCEPTIONS
throw bad_array_new_length();
# else
_LIBCPP_VERBOSE_ABORT("bad_array_new_length was thrown in -fno-exceptions mode");
# endif
}
# if _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION && !defined(_LIBCPP_ABI_VCRUNTIME)
# ifndef _LIBCPP_CXX03_LANG
enum class align_val_t : size_t {};
# else
enum align_val_t { __zero = 0, __max = (size_t)-1 };
# endif
# endif
# if _LIBCPP_STD_VER >= 20
// Enable the declaration even if the compiler doesn't support the language
// feature.
struct destroying_delete_t {
explicit destroying_delete_t() = default;
};
inline constexpr destroying_delete_t destroying_delete{};
# endif // _LIBCPP_STD_VER >= 20
} // namespace std
# if defined(_LIBCPP_CXX03_LANG)
# define _THROW_BAD_ALLOC throw(std::bad_alloc)
# else
# define _THROW_BAD_ALLOC
# endif
# if !defined(_LIBCPP_ABI_VCRUNTIME)
[[__nodiscard__]] _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz) _THROW_BAD_ALLOC;
[[__nodiscard__]] _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, const std::nothrow_t&) _NOEXCEPT
_LIBCPP_NOALIAS;
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p) _NOEXCEPT;
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, const std::nothrow_t&) _NOEXCEPT;
# if _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::size_t __sz) _NOEXCEPT;
# endif
[[__nodiscard__]] _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz) _THROW_BAD_ALLOC;
[[__nodiscard__]] _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz, const std::nothrow_t&) _NOEXCEPT
_LIBCPP_NOALIAS;
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p) _NOEXCEPT;
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, const std::nothrow_t&) _NOEXCEPT;
# if _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::size_t __sz) _NOEXCEPT;
# endif
# if _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION
[[__nodiscard__]] _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, std::align_val_t) _THROW_BAD_ALLOC;
[[__nodiscard__]] _LIBCPP_OVERRIDABLE_FUNC_VIS void*
operator new(std::size_t __sz, std::align_val_t, const std::nothrow_t&) _NOEXCEPT _LIBCPP_NOALIAS;
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::align_val_t) _NOEXCEPT;
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::align_val_t, const std::nothrow_t&) _NOEXCEPT;
# if _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::size_t __sz, std::align_val_t) _NOEXCEPT;
# endif
[[__nodiscard__]] _LIBCPP_OVERRIDABLE_FUNC_VIS void*
operator new[](std::size_t __sz, std::align_val_t) _THROW_BAD_ALLOC;
[[__nodiscard__]] _LIBCPP_OVERRIDABLE_FUNC_VIS void*
operator new[](std::size_t __sz, std::align_val_t, const std::nothrow_t&) _NOEXCEPT _LIBCPP_NOALIAS;
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::align_val_t) _NOEXCEPT;
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::align_val_t, const std::nothrow_t&) _NOEXCEPT;
# if _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::size_t __sz, std::align_val_t) _NOEXCEPT;
# endif
# endif
[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void*
operator new(std::size_t, void* __p) _NOEXCEPT {
return __p;
}
[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void*
operator new[](std::size_t, void* __p) _NOEXCEPT {
return __p;
}
inline _LIBCPP_HIDE_FROM_ABI void operator delete(void*, void*) _NOEXCEPT {}
inline _LIBCPP_HIDE_FROM_ABI void operator delete[](void*, void*) _NOEXCEPT {}
# endif // !_LIBCPP_ABI_VCRUNTIME
_LIBCPP_BEGIN_NAMESPACE_STD
_LIBCPP_CONSTEXPR inline _LIBCPP_HIDE_FROM_ABI bool __is_overaligned_for_new(size_t __align) _NOEXCEPT {
# ifdef __STDCPP_DEFAULT_NEW_ALIGNMENT__
return __align > __STDCPP_DEFAULT_NEW_ALIGNMENT__;
# else
return __align > _LIBCPP_ALIGNOF(max_align_t);
# endif
}
template <class... _Args>
_LIBCPP_HIDE_FROM_ABI void* __libcpp_operator_new(_Args... __args) {
# if __has_builtin(__builtin_operator_new) && __has_builtin(__builtin_operator_delete)
return __builtin_operator_new(__args...);
# else
return ::operator new(__args...);
# endif
}
template <class... _Args>
_LIBCPP_HIDE_FROM_ABI void __libcpp_operator_delete(_Args... __args) _NOEXCEPT {
# if __has_builtin(__builtin_operator_new) && __has_builtin(__builtin_operator_delete)
__builtin_operator_delete(__args...);
# else
::operator delete(__args...);
# endif
}
inline _LIBCPP_HIDE_FROM_ABI void* __libcpp_allocate(size_t __size, size_t __align) {
# if _LIBCPP_HAS_ALIGNED_ALLOCATION
if (__is_overaligned_for_new(__align)) {
const align_val_t __align_val = static_cast<align_val_t>(__align);
return __libcpp_operator_new(__size, __align_val);
}
# endif
(void)__align;
return __libcpp_operator_new(__size);
}
template <class... _Args>
_LIBCPP_HIDE_FROM_ABI void __do_deallocate_handle_size(void* __ptr, size_t __size, _Args... __args) _NOEXCEPT {
# if !_LIBCPP_HAS_SIZED_DEALLOCATION
(void)__size;
return std::__libcpp_operator_delete(__ptr, __args...);
# else
return std::__libcpp_operator_delete(__ptr, __size, __args...);
# endif
}
inline _LIBCPP_HIDE_FROM_ABI void __libcpp_deallocate(void* __ptr, size_t __size, size_t __align) _NOEXCEPT {
# if !_LIBCPP_HAS_ALIGNED_ALLOCATION
(void)__align;
return __do_deallocate_handle_size(__ptr, __size);
# else
if (__is_overaligned_for_new(__align)) {
const align_val_t __align_val = static_cast<align_val_t>(__align);
return __do_deallocate_handle_size(__ptr, __size, __align_val);
} else {
return __do_deallocate_handle_size(__ptr, __size);
}
# endif
}
inline _LIBCPP_HIDE_FROM_ABI void __libcpp_deallocate_unsized(void* __ptr, size_t __align) _NOEXCEPT {
# if !_LIBCPP_HAS_ALIGNED_ALLOCATION
(void)__align;
return __libcpp_operator_delete(__ptr);
# else
if (__is_overaligned_for_new(__align)) {
const align_val_t __align_val = static_cast<align_val_t>(__align);
return __libcpp_operator_delete(__ptr, __align_val);
} else {
return __libcpp_operator_delete(__ptr);
}
# endif
}
template <class _Tp>
[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp* __launder(_Tp* __p) _NOEXCEPT {
static_assert(!(is_function<_Tp>::value), "can't launder functions");
static_assert(!is_void<_Tp>::value, "can't launder cv-void");
return __builtin_launder(__p);
}
# if _LIBCPP_STD_VER >= 17
template <class _Tp>
[[nodiscard]] inline _LIBCPP_HIDE_FROM_ABI constexpr _Tp* launder(_Tp* __p) noexcept {
return std::__launder(__p);
}
# endif
# if _LIBCPP_STD_VER >= 17
# if defined(__GCC_DESTRUCTIVE_SIZE) && defined(__GCC_CONSTRUCTIVE_SIZE)
inline constexpr size_t hardware_destructive_interference_size = __GCC_DESTRUCTIVE_SIZE;
inline constexpr size_t hardware_constructive_interference_size = __GCC_CONSTRUCTIVE_SIZE;
# endif // defined(__GCC_DESTRUCTIVE_SIZE) && defined(__GCC_CONSTRUCTIVE_SIZE)
# endif // _LIBCPP_STD_VER >= 17
_LIBCPP_END_NAMESPACE_STD
# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
# include <cstddef>
# include <cstdlib>

View File

@ -250,6 +250,7 @@ charconv cstdlib
charconv cstring
charconv iosfwd
charconv limits
charconv new
charconv type_traits
charconv version
chrono algorithm

1 algorithm atomic
250 charconv cstring
251 charconv iosfwd
252 charconv limits
253 charconv new
254 charconv type_traits
255 charconv version
256 chrono algorithm

View File

@ -250,6 +250,7 @@ charconv cstdlib
charconv cstring
charconv iosfwd
charconv limits
charconv new
charconv type_traits
charconv version
chrono algorithm

1 algorithm atomic
250 charconv cstring
251 charconv iosfwd
252 charconv limits
253 charconv new
254 charconv type_traits
255 charconv version
256 chrono algorithm

View File

@ -255,6 +255,7 @@ charconv cstdlib
charconv cstring
charconv iosfwd
charconv limits
charconv new
charconv type_traits
charconv version
chrono algorithm

1 algorithm atomic
255 charconv cstring
256 charconv iosfwd
257 charconv limits
258 charconv new
259 charconv type_traits
260 charconv version
261 chrono algorithm

View File

@ -28,7 +28,6 @@ array cwchar
array cwctype
array initializer_list
array limits
array new
array stdexcept
array version
atomic climits
@ -43,7 +42,6 @@ barrier cstdint
barrier cstring
barrier ctime
barrier limits
barrier new
barrier ratio
barrier version
bit cstdint
@ -102,7 +100,6 @@ charconv cerrno
charconv cstdint
charconv initializer_list
charconv limits
charconv new
charconv version
chrono array
chrono bitset
@ -271,7 +268,6 @@ exception version
execution version
expected cstdint
expected initializer_list
expected new
expected version
experimental/iterator bitset
experimental/iterator cctype
@ -672,7 +668,6 @@ mdspan cwchar
mdspan cwctype
mdspan initializer_list
mdspan limits
mdspan new
mdspan span
mdspan stdexcept
mdspan version
@ -882,7 +877,6 @@ regex version
scoped_allocator compare
scoped_allocator cstdint
scoped_allocator limits
scoped_allocator new
scoped_allocator tuple
scoped_allocator version
semaphore climits
@ -1018,7 +1012,6 @@ string_view cwctype
string_view initializer_list
string_view iosfwd
string_view limits
string_view new
string_view stdexcept
string_view version
strstream bitset

1 algorithm cctype
28 array cwctype
29 array initializer_list
30 array limits
array new
31 array stdexcept
32 array version
33 atomic climits
42 barrier cstring
43 barrier ctime
44 barrier limits
barrier new
45 barrier ratio
46 barrier version
47 bit cstdint
100 charconv cstdint
101 charconv initializer_list
102 charconv limits
charconv new
103 charconv version
104 chrono array
105 chrono bitset
268 execution version
269 expected cstdint
270 expected initializer_list
expected new
271 expected version
272 experimental/iterator bitset
273 experimental/iterator cctype
668 mdspan cwctype
669 mdspan initializer_list
670 mdspan limits
mdspan new
671 mdspan span
672 mdspan stdexcept
673 mdspan version
877 scoped_allocator compare
878 scoped_allocator cstdint
879 scoped_allocator limits
scoped_allocator new
880 scoped_allocator tuple
881 scoped_allocator version
882 semaphore climits
1012 string_view initializer_list
1013 string_view iosfwd
1014 string_view limits
string_view new
1015 string_view stdexcept
1016 string_view version
1017 strstream bitset

View File

@ -28,7 +28,6 @@ array cwchar
array cwctype
array initializer_list
array limits
array new
array stdexcept
array version
atomic climits
@ -43,7 +42,6 @@ barrier cstdint
barrier cstring
barrier ctime
barrier limits
barrier new
barrier ratio
barrier version
bit cstdint
@ -102,7 +100,6 @@ charconv cerrno
charconv cstdint
charconv initializer_list
charconv limits
charconv new
charconv version
chrono array
chrono bitset
@ -271,7 +268,6 @@ exception version
execution version
expected cstdint
expected initializer_list
expected new
expected version
experimental/iterator bitset
experimental/iterator cctype
@ -671,7 +667,6 @@ mdspan cwchar
mdspan cwctype
mdspan initializer_list
mdspan limits
mdspan new
mdspan span
mdspan stdexcept
mdspan version
@ -881,7 +876,6 @@ regex version
scoped_allocator compare
scoped_allocator cstdint
scoped_allocator limits
scoped_allocator new
scoped_allocator tuple
scoped_allocator version
semaphore climits
@ -1017,7 +1011,6 @@ string_view cwctype
string_view initializer_list
string_view iosfwd
string_view limits
string_view new
string_view stdexcept
string_view version
strstream bitset

1 algorithm cctype
28 array cwctype
29 array initializer_list
30 array limits
array new
31 array stdexcept
32 array version
33 atomic climits
42 barrier cstring
43 barrier ctime
44 barrier limits
barrier new
45 barrier ratio
46 barrier version
47 bit cstdint
100 charconv cstdint
101 charconv initializer_list
102 charconv limits
charconv new
103 charconv version
104 chrono array
105 chrono bitset
268 execution version
269 expected cstdint
270 expected initializer_list
expected new
271 expected version
272 experimental/iterator bitset
273 experimental/iterator cctype
667 mdspan cwctype
668 mdspan initializer_list
669 mdspan limits
mdspan new
670 mdspan span
671 mdspan stdexcept
672 mdspan version
876 scoped_allocator compare
877 scoped_allocator cstdint
878 scoped_allocator limits
scoped_allocator new
879 scoped_allocator tuple
880 scoped_allocator version
881 semaphore climits
1011 string_view initializer_list
1012 string_view iosfwd
1013 string_view limits
string_view new
1014 string_view stdexcept
1015 string_view version
1016 strstream bitset

View File

@ -9,8 +9,9 @@
// test bad_alloc
#include <new>
#include <type_traits>
#include <cassert>
#include <exception>
#include <type_traits>
#include "test_macros.h"

View File

@ -10,6 +10,7 @@
#include <new>
#include <cassert>
#include <cstddef>
#include "test_macros.h"

View File

@ -20,17 +20,17 @@
void foo() {}
int main(int, char**)
{
void *p = nullptr;
(void) std::launder(( void *) nullptr);
(void) std::launder((const void *) nullptr);
(void) std::launder(( volatile void *) nullptr);
(void) std::launder((const volatile void *) nullptr); // expected-error-re@new:* 4 {{static assertion failed{{.*}}can't launder cv-void}}
// expected-error@new:* 0-4 {{void pointer argument to '__builtin_launder' is not allowed}}
int main(int, char**) {
void* p = nullptr;
(void)std::launder((void*)nullptr);
(void)std::launder((const void*)nullptr);
(void)std::launder((volatile void*)nullptr);
(void)std::launder(
(const volatile void*)nullptr); // expected-error-re@*:* 4 {{static assertion failed{{.*}}can't launder cv-void}}
// expected-error@*:* 0-4 {{void pointer argument to '__builtin_launder' is not allowed}}
(void) std::launder(foo); // expected-error-re@new:* 1 {{static assertion failed{{.*}}can't launder functions}}
// expected-error@new:* 0-1 {{function pointer argument to '__builtin_launder' is not allowed}}
(void)std::launder(foo); // expected-error-re@*:* 1 {{static assertion failed{{.*}}can't launder functions}}
// expected-error@*:* 0-1 {{function pointer argument to '__builtin_launder' is not allowed}}
return 0;
}

View File

@ -14,6 +14,7 @@
#include <memory>
#include <cassert>
#include <cstddef>
#include <new>
#include "test_macros.h"

View File

@ -12,8 +12,9 @@
// XFAIL: using-built-library-before-llvm-9
#include "cxxabi.h"
#include <new>
#include <cassert>
#include <cstddef>
#include <new>
void dummy_ctor(void*) { assert(false && "should not be called"); }
void dummy_dtor(void*) { assert(false && "should not be called"); }