#if !__has_builtin(__builtin_operator_new) || !__has_builtin(__builtin_operator_delete)
#error builtins should always be available
#endif
#if __has_builtin(__builtin_operator_new) != 201802L || \
__has_builtin(__builtin_operator_delete) != 201802L
#error builtin should report updated value
#endif
typedef __SIZE_TYPE__ size_t;
namespace std {
struct nothrow_t {};
#if __cplusplus >= 201103L
enum class align_val_t : size_t {};
#else
enum align_val_t {
# ifndef _WIN32
__zero = 0, __max = (size_t)-1
# endif
};
#endif
}
std::nothrow_t nothrow;
void *operator new(size_t); void operator delete(void *);
void *operator new(size_t, void*) throw(); void operator delete(void *, void *)throw(); void *operator new[](size_t, void*) throw();
void operator delete[](void*, void*) throw();
void *operator new(size_t, const std::nothrow_t &) throw(); void *operator new[](size_t, const std::nothrow_t &) throw();
void operator delete(void *, const std::nothrow_t &)throw(); void operator delete[](void *, const std::nothrow_t &) throw();
void* operator new ( size_t count, std::align_val_t al); void operator delete(void *, std::align_val_t); #ifndef __cpp_aligned_new
#endif
void *operator new[](size_t count, std::align_val_t al);
void operator delete[](void*, std::align_val_t);
void operator delete(void *, size_t); #ifndef __cpp_sized_deallocation
#endif
void operator delete[](void*, size_t);
void *operator new(size_t, void*, bool) throw(); void *operator new[](size_t, void*, bool) throw();
void *NP = 0;
void test_typo_in_args() {
__builtin_operator_new(DNE); __builtin_operator_new(DNE, DNE2); __builtin_operator_delete(DNE); __builtin_operator_delete(DNE, DNE2); }
void test_arg_types() {
__builtin_operator_new(NP); __builtin_operator_new(NP, std::align_val_t(0)); }
void test_return_type() {
int w = __builtin_operator_new(42); int y = __builtin_operator_delete(NP); }
void test_aligned_new() {
#ifdef __cpp_aligned_new
void *p = __builtin_operator_new(42, std::align_val_t(2));
__builtin_operator_delete(p, std::align_val_t(2));
#else
void *p = __builtin_operator_new(42, std::align_val_t(2)); __builtin_operator_delete(p, std::align_val_t(2)); #endif
}
void test_sized_delete() {
#ifdef __cpp_sized_deallocation
__builtin_operator_delete(NP, 4);
#else
__builtin_operator_delete(NP, 4); #endif
}
void *operator new(size_t, bool); void operator delete(void *, bool);
void test_non_usual() {
__builtin_operator_new(42, true); __builtin_operator_delete(NP, false); }
template <int ID>
struct Tag {};
struct ConvertsToTypes {
operator std::align_val_t() const;
operator Tag<0>() const;
};
void *operator new(size_t, Tag<0>); void operator delete(void *, Tag<0>);
void test_ambiguous() {
#ifdef __cpp_aligned_new
ConvertsToTypes cvt;
__builtin_operator_new(42, cvt); __builtin_operator_delete(NP, cvt); #endif
}
void test_no_args() {
__builtin_operator_new(); __builtin_operator_delete(); }
void test_no_matching_fn() {
Tag<1> tag;
__builtin_operator_new(42, tag); __builtin_operator_delete(NP, tag); }
template <class Tp, class Up, class RetT>
void test_dependent_call(Tp new_arg, Up delete_arg, RetT) {
RetT ret = __builtin_operator_new(new_arg);
__builtin_operator_delete(delete_arg);
}
template void test_dependent_call(int, int*, void*);
void test_const_attribute() {
__builtin_operator_new(42); #ifdef __cpp_aligned_new
__builtin_operator_new(42, std::align_val_t(8)); #endif
}