| 1 |
// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++26 -Wno-ext-cxx-type-aware-allocators -fexceptions -fcxx-exceptions -fsized-deallocation -faligned-allocation |
| 2 |
// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++26 -Wno-ext-cxx-type-aware-allocators -fexceptions -fcxx-exceptions -fno-sized-deallocation -faligned-allocation |
| 3 |
// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++26 -Wno-ext-cxx-type-aware-allocators -fexceptions -fcxx-exceptions -fno-sized-deallocation -fno-aligned-allocation |
| 4 |
// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++26 -Wno-ext-cxx-type-aware-allocators -fexceptions -fcxx-exceptions -fsized-deallocation -fno-aligned-allocation |
| 5 |
|
| 6 |
namespace std { |
| 7 |
template <class T> struct type_identity {}; |
| 8 |
enum class align_val_t : __SIZE_TYPE__ {}; |
| 9 |
struct destroying_delete_t { explicit destroying_delete_t() = default; }; |
| 10 |
} |
| 11 |
|
| 12 |
using size_t = __SIZE_TYPE__; |
| 13 |
struct Context; |
| 14 |
struct S1 { |
| 15 |
S1(); |
| 16 |
}; |
| 17 |
void *operator new(std::type_identity<S1>, size_t, std::align_val_t, Context&); |
| 18 |
void operator delete(std::type_identity<S1>, void*, size_t, std::align_val_t, Context&) = delete; // #1 |
| 19 |
|
| 20 |
struct S2 { |
| 21 |
S2(); |
| 22 |
template<typename T> void *operator new(std::type_identity<T>, size_t, std::align_val_t, Context&); |
| 23 |
template<typename T> void operator delete(std::type_identity<T>, void*, size_t, std::align_val_t, Context&) = delete; // #2 |
| 24 |
template<typename T> void operator delete(std::type_identity<T>, void*, size_t, std::align_val_t) = delete; // #3 |
| 25 |
}; |
| 26 |
|
| 27 |
struct S3 { |
| 28 |
S3(); |
| 29 |
template<typename T> void *operator new(std::type_identity<T>, size_t, std::align_val_t); |
| 30 |
template<typename T> void operator delete(std::type_identity<T>, void*, size_t, std::align_val_t) = delete; // #4 |
| 31 |
}; |
| 32 |
|
| 33 |
struct S4 { |
| 34 |
S4(); |
| 35 |
template<typename T> void *operator new(std::type_identity<T>, size_t, std::align_val_t, Context&); // #S4_new |
| 36 |
template<typename T> void operator delete(std::type_identity<T>, void*, size_t, std::align_val_t); // #5 |
| 37 |
}; |
| 38 |
|
| 39 |
void test(Context& Ctx) { |
| 40 |
S1 *s1 = new (Ctx) S1; |
| 41 |
// expected-error@-1 {{attempt to use a deleted function}} |
| 42 |
// expected-note@#1 {{'operator delete' has been explicitly marked deleted here}} |
| 43 |
delete s1; |
| 44 |
S2 *s2_1 = new (Ctx) S2; |
| 45 |
// expected-error@-1 {{attempt to use a deleted function}} |
| 46 |
// expected-note@#2 {{'operator delete<S2>' has been explicitly marked deleted here}} |
| 47 |
// expected-note@#3 {{'operator delete<S2>' has been explicitly marked deleted here}} |
| 48 |
delete s2_1; |
| 49 |
// expected-error@-1 {{attempt to use a deleted function}} |
| 50 |
// expected-note@#2 {{'operator delete<S2>' has been explicitly marked deleted here}} |
| 51 |
S2 *s2_2 = new (std::align_val_t(128), Ctx) S2; |
| 52 |
// expected-error@-1 {{attempt to use a deleted function}} |
| 53 |
delete s2_2; |
| 54 |
// expected-error@-1 {{attempt to use a deleted function}} |
| 55 |
// expected-note@#3 {{'operator delete<S2>' has been explicitly marked deleted here}} |
| 56 |
S3 *s3_1 = new S3; |
| 57 |
// expected-error@-1 {{attempt to use a deleted function}} |
| 58 |
// expected-note@#4 {{'operator delete<S3>' has been explicitly marked deleted here}} |
| 59 |
delete s3_1; |
| 60 |
// expected-error@-1 {{attempt to use a deleted function}} |
| 61 |
// expected-note@#4 {{'operator delete<S3>' has been explicitly marked deleted here}} |
| 62 |
S3 *s3_2 = new (std::align_val_t(128)) S3; |
| 63 |
// expected-error@-1 {{attempt to use a deleted function}} |
| 64 |
// expected-note@#4 {{'operator delete<S3>' has been explicitly marked deleted here}} |
| 65 |
delete s3_2; |
| 66 |
// expected-error@-1 {{attempt to use a deleted function}} |
| 67 |
// expected-note@#4 {{'operator delete<S3>' has been explicitly marked deleted here}} |
| 68 |
|
| 69 |
S4 *s4_1 = new (Ctx) S4; |
| 70 |
// expected-error@-1 {{type aware 'operator new' requires a matching type aware placement 'operator delete' to be declared in the same scope}} |
| 71 |
// expected-note@#S4_new {{type aware 'operator new' declared here in 'S4'}} |
| 72 |
delete s4_1; |
| 73 |
} |