1 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.12.0 -fexceptions -faligned-alloc-unavailable -std=c++1z -verify %s 2 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.12.0 -fexceptions -std=c++1z -verify -DNO_ERRORS %s 3 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.12.0 -fexceptions -faligned-allocation -faligned-alloc-unavailable -std=c++14 -verify %s 4 5 namespace std { 6 typedef decltype(sizeof(0)) size_t; 7 enum class align_val_t : std::size_t {}; 8 struct nothrow_t {}; 9 nothrow_t nothrow; 10 } 11 12 void *operator new(std::size_t __sz, const std::nothrow_t&) noexcept; 13 void *operator new[](std::size_t __sz, const std::nothrow_t&) noexcept; 14 15 void *operator new(std::size_t __sz, std::align_val_t, const std::nothrow_t&) noexcept; 16 void *operator new[](std::size_t __sz, std::align_val_t, const std::nothrow_t&) noexcept; 17 void operator delete(void *, std::align_val_t, const std::nothrow_t&); 18 void operator delete[](void *, std::align_val_t, const std::nothrow_t&); 19 void operator delete(void*, std::size_t, std::align_val_t) noexcept; 20 void operator delete[](void*, std::size_t, std::align_val_t) noexcept; 21 22 void *operator new(std::size_t, std::align_val_t, long long); 23 24 struct alignas(256) OveralignedS { 25 int x[16]; 26 }; 27 28 struct S { 29 int x[16]; 30 }; 31 32 void test() { 33 auto *p = new S; 34 delete p; 35 p = new (std::nothrow) S; 36 37 auto *pa = new S[4]; 38 delete[] pa; 39 pa = new (std::nothrow) S[4]; 40 } 41 42 void testOveraligned() { 43 auto *p = new OveralignedS; 44 p = new ((std::align_val_t)8) OveralignedS; 45 delete p; 46 p = new (std::nothrow) OveralignedS; 47 48 auto *pa = new OveralignedS[4]; 49 pa = new ((std::align_val_t)8) OveralignedS[4]; 50 delete[] pa; 51 pa = new (std::nothrow) OveralignedS[4]; 52 // No error here since it is not calling a replaceable allocation function. 53 p = new ((std::align_val_t)8, 10LL) OveralignedS; 54 } 55 56 #ifdef NO_ERRORS 57 // expected-no-diagnostics 58 #else 59 // expected-error@-16 {{aligned allocation function of type 'void *(unsigned long, enum std::align_val_t)' possibly unavailable on}} 60 // expected-note@-17 {{if you supply your own aligned allocation functions}} 61 // expected-error@-18 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' possibly unavailable on}} 62 // expected-note@-19 {{if you supply your own aligned allocation functions}} 63 64 // expected-error@-20 {{aligned allocation function of type 'void *(unsigned long, enum std::align_val_t)' possibly unavailable on}} 65 // expected-note@-21 {{if you supply your own aligned allocation functions}} 66 // expected-error@-22 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' possibly unavailable on}} 67 // expected-note@-23 {{if you supply your own aligned allocation functions}} 68 69 // expected-error@-24 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' possibly unavailable on}} 70 // expected-note@-25 {{if you supply your own aligned allocation functions}} 71 72 // expected-error@-26 {{aligned allocation function of type 'void *(std::size_t, std::align_val_t, const std::nothrow_t &) noexcept' possibly unavailable on}} 73 // expected-note@-27 {{if you supply your own aligned allocation functions}} 74 // expected-error@-28 {{aligned deallocation function of type 'void (void *, std::align_val_t, const std::nothrow_t &) noexcept' possibly unavailable on}} 75 // expected-note@-29 {{if you supply your own aligned allocation functions}} 76 77 // expected-error@-29 {{aligned allocation function of type 'void *(unsigned long, enum std::align_val_t)' possibly unavailable on}} 78 // expected-note@-30 {{if you supply your own aligned allocation functions}} 79 // expected-error@-31 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' possibly unavailable on}} 80 // expected-note@-32 {{if you supply your own aligned allocation functions}} 81 82 // expected-error@-33 {{aligned allocation function of type 'void *(unsigned long, enum std::align_val_t)' possibly unavailable on}} 83 // expected-note@-34 {{if you supply your own aligned allocation functions}} 84 // expected-error@-35 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' possibly unavailable on}} 85 // expected-note@-36 {{if you supply your own aligned allocation functions}} 86 87 // expected-error@-37 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' possibly unavailable on}} 88 // expected-note@-38 {{if you supply your own aligned allocation functions}} 89 90 // expected-error@-39 {{aligned allocation function of type 'void *(std::size_t, std::align_val_t, const std::nothrow_t &) noexcept' possibly unavailable on}} 91 // expected-note@-40 {{if you supply your own aligned allocation functions}} 92 // expected-error@-41 {{aligned deallocation function of type 'void (void *, std::align_val_t, const std::nothrow_t &) noexcept' possibly unavailable on}} 93 // expected-note@-42 {{if you supply your own aligned allocation functions}} 94 95 #endif 96 97 // No errors if user-defined aligned allocation functions are available. 98 void *operator new(std::size_t __sz, std::align_val_t) { 99 static char array[256]; 100 return &array; 101 } 102 103 void operator delete(void *p, std::align_val_t) { 104 } 105 106 void testOveraligned2() { 107 auto p = new ((std::align_val_t)8) OveralignedS; 108 delete p; 109 } 110