59 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++26 -Wno-ext-cxx-type-aware-allocators -fexceptions -fsized-deallocation -faligned-allocation -Wall -Wpedantic2// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++26 -Wno-ext-cxx-type-aware-allocators -fexceptions -fno-sized-deallocation -faligned-allocation -Wall -Wpedantic3// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++26 -Wno-ext-cxx-type-aware-allocators -fexceptions -fno-sized-deallocation -fno-aligned-allocation -Wall -Wpedantic4// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++26 -Wno-ext-cxx-type-aware-allocators -fexceptions -fsized-deallocation -fno-aligned-allocation -Wall -Wpedantic5 6namespace 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 12using size_t = __SIZE_TYPE__;13 14struct BasicTypeAwareArrayAllocator {15 template <typename T> void *operator new[](std::type_identity<T>, size_t, std::align_val_t) = delete; // #116 template <typename T> void operator delete[](std::type_identity<T>, void*, size_t, std::align_val_t) = delete; // #217};18void *operator new[](std::type_identity<BasicTypeAwareArrayAllocator>, size_t, std::align_val_t);19void operator delete[](std::type_identity<BasicTypeAwareArrayAllocator>, void*, size_t, std::align_val_t);20 21struct BasicTypeAwareNonArrayAllocator {22 template <typename T> void *operator new[](std::type_identity<T>, size_t, std::align_val_t);23 template <typename T> void operator delete[](std::type_identity<T>, void*, size_t, std::align_val_t);24 void *operator new(size_t) = delete;25 void operator delete(void*) = delete;26};27 28struct WorkingTypeAwareAllocator {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);31};32 33void *operator new[](std::type_identity<WorkingTypeAwareAllocator>, size_t, std::align_val_t) = delete;34void operator delete[](std::type_identity<WorkingTypeAwareAllocator>, void*, size_t, std::align_val_t) = delete;35 36 37void test() {38 BasicTypeAwareArrayAllocator *A0 = new BasicTypeAwareArrayAllocator[10];39 // expected-error@-1 {{call to deleted function 'operator new[]'}}40 // expected-note@#1 {{candidate function [with T = BasicTypeAwareArrayAllocator] has been explicitly deleted}}41 delete [] A0;42 // expected-error@-1 {{attempt to use a deleted function}}43 // expected-note@#2 {{'operator delete[]<BasicTypeAwareArrayAllocator>' has been explicitly marked deleted here}}44 45 BasicTypeAwareNonArrayAllocator *A1 = new BasicTypeAwareNonArrayAllocator[10];46 delete [] A1;47 48 WorkingTypeAwareAllocator *A2 = new WorkingTypeAwareAllocator[10];49 // expected-note@-1 {{allocated with 'new[]' here}}50 delete A2;51 // expected-warning@-1 {{'delete' applied to a pointer that was allocated with 'new[]'; did you mean 'delete[]'?}}52 53 WorkingTypeAwareAllocator *A3 = new WorkingTypeAwareAllocator;54 // expected-note@-1 {{allocated with 'new' here}}55 delete [] A3;56 // expected-warning@-1 {{'delete[]' applied to a pointer that was allocated with 'new'; did you mean 'delete'?}}57 58}59