| 1 |
// RUN: %clang_cc1 -fsyntax-only -Wno-ext-cxx-type-aware-allocators -verify %s -DNO_TADD -std=c++26 -fsized-deallocation -faligned-allocation |
| 2 |
// RUN: %clang_cc1 -fsyntax-only -Wno-ext-cxx-type-aware-allocators -verify %s -DNO_TADD -std=c++26 -fno-sized-deallocation -faligned-allocation |
| 3 |
// RUN: %clang_cc1 -fsyntax-only -Wno-ext-cxx-type-aware-allocators -verify %s -DNO_TADD -std=c++26 -fno-sized-deallocation -fno-aligned-allocation |
| 4 |
// RUN: %clang_cc1 -fsyntax-only -Wno-ext-cxx-type-aware-allocators -verify %s -DNO_TADD -std=c++26 -fsized-deallocation -fno-aligned-allocation |
| 5 |
namespace std { |
| 6 |
template <class T> struct type_identity { |
| 7 |
typedef T type; |
| 8 |
}; |
| 9 |
enum class align_val_t : __SIZE_TYPE__ {}; |
| 10 |
struct destroying_delete_t { explicit destroying_delete_t() = default; }; |
| 11 |
} |
| 12 |
|
| 13 |
using size_t = __SIZE_TYPE__; |
| 14 |
|
| 15 |
|
| 16 |
template <class Tp> struct is_const { |
| 17 |
static const bool value = false; |
| 18 |
}; |
| 19 |
template <class Tp> struct is_const<Tp const> { |
| 20 |
static const bool value = true; |
| 21 |
}; |
| 22 |
|
| 23 |
template <class Tp> struct is_volatile { |
| 24 |
static const bool value = false; |
| 25 |
}; |
| 26 |
template <class Tp> struct is_volatile<Tp volatile> { |
| 27 |
static const bool value = true; |
| 28 |
}; |
| 29 |
|
| 30 |
template <class T> static const bool is_const_v = is_const<T>::value; |
| 31 |
template <class T> static const bool is_volatile_v = is_volatile<T>::value; |
| 32 |
|
| 33 |
struct VerifyQualifiers { |
| 34 |
template <typename T> void *operator new(std::type_identity<T>, size_t, std::align_val_t) throw() { |
| 35 |
static_assert(is_const_v<T> == false); // #1 |
| 36 |
static_assert(is_volatile_v<T> == false); // #2 |
| 37 |
return 0; |
| 38 |
} |
| 39 |
template <typename T> void operator delete(std::type_identity<T>, void*, size_t, std::align_val_t) { |
| 40 |
static_assert(is_const_v<T> == false); // #3 |
| 41 |
static_assert(is_volatile_v<T> == false); // #4 |
| 42 |
} |
| 43 |
template <typename T> void *operator new(std::type_identity<_Atomic T>, size_t, std::align_val_t) throw() { |
| 44 |
static_assert(is_const_v<T> == false); |
| 45 |
static_assert(is_volatile_v<T> == false); |
| 46 |
} |
| 47 |
}; |
| 48 |
|
| 49 |
void *operator new(std::type_identity<VerifyQualifiers> type, size_t, std::align_val_t) throw() { // #11 |
| 50 |
static_assert(is_const_v<typename decltype(type)::type> == false); // #5 |
| 51 |
static_assert(is_volatile_v<typename decltype(type)::type> == false); // #6 |
| 52 |
return 0; |
| 53 |
} |
| 54 |
|
| 55 |
void operator delete(std::type_identity<VerifyQualifiers> type, void*, size_t, std::align_val_t) { |
| 56 |
static_assert(is_const_v<typename decltype(type)::type> == false); // #7 |
| 57 |
static_assert(is_volatile_v<typename decltype(type)::type> == false); // #8 |
| 58 |
} |
| 59 |
|
| 60 |
void *operator new(std::type_identity<int>, size_t, std::align_val_t) throw() = delete; // #12 |
| 61 |
void operator delete(std::type_identity<int>, void*, size_t, std::align_val_t) = delete; |
| 62 |
|
| 63 |
struct TestAtomic1 { |
| 64 |
|
| 65 |
}; |
| 66 |
struct TestAtomic2 { |
| 67 |
}; |
| 68 |
|
| 69 |
void *operator new(std::type_identity<TestAtomic1>, size_t, std::align_val_t) throw() = delete; // #13 |
| 70 |
void operator delete(std::type_identity<_Atomic TestAtomic1>, void*, size_t, std::align_val_t) = delete; // #9 |
| 71 |
void *operator new(std::type_identity<_Atomic TestAtomic2>, size_t, std::align_val_t) = delete; // #10 |
| 72 |
void operator delete(std::type_identity<TestAtomic2>, void*, size_t, std::align_val_t) = delete; |
| 73 |
|
| 74 |
// Success tests |
| 75 |
void test_member_allocators() { |
| 76 |
auto *unqualified_obj = new VerifyQualifiers(); |
| 77 |
delete unqualified_obj; |
| 78 |
auto *const_obj = new const VerifyQualifiers(); |
| 79 |
delete const_obj; |
| 80 |
auto *volatile_obj = new volatile VerifyQualifiers(); |
| 81 |
delete volatile_obj; |
| 82 |
auto *const_volatile_obj = new const volatile VerifyQualifiers(); |
| 83 |
delete const_volatile_obj; |
| 84 |
auto *atomic_obj = new _Atomic VerifyQualifiers(); |
| 85 |
delete atomic_obj; |
| 86 |
auto *atomic_test1 = new _Atomic TestAtomic1; |
| 87 |
delete atomic_test1; |
| 88 |
// expected-error@-1 {{attempt to use a deleted function}} |
| 89 |
// expected-note@#9 {{'operator delete' has been explicitly marked deleted here}} |
| 90 |
auto *atomic_test2 = new _Atomic TestAtomic2; |
| 91 |
// expected-error@-1 {{call to deleted function 'operator new'}} |
| 92 |
// expected-note@#10 {{candidate function has been explicitly deleted}} |
| 93 |
// expected-note@#11 {{candidate function not viable}} |
| 94 |
// expected-note@#12 {{candidate function not viable}} |
| 95 |
// expected-note@#13 {{candidate function not viable}} |
| 96 |
delete atomic_test2; |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
void test_global_allocators() { |
| 102 |
auto *unqualified_obj = ::new VerifyQualifiers(); |
| 103 |
::delete unqualified_obj; |
| 104 |
auto *const_obj = ::new const VerifyQualifiers(); |
| 105 |
::delete const_obj; |
| 106 |
auto *volatile_obj = ::new volatile VerifyQualifiers(); |
| 107 |
::delete volatile_obj; |
| 108 |
auto *const_volatile_obj = ::new const volatile VerifyQualifiers(); |
| 109 |
::delete const_volatile_obj; |
| 110 |
_Atomic VerifyQualifiers *atomic_obj = ::new _Atomic VerifyQualifiers(); |
| 111 |
::delete atomic_obj; |
| 112 |
_Atomic int *atomic_int = new _Atomic int; |
| 113 |
delete atomic_int; |
| 114 |
} |