| 1 | // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -fexceptions %s |
| 2 | // RUN: %clang_cc1 -fsyntax-only -verify -std=c++14 -fexceptions %s |
| 3 | // RUN: %clang_cc1 -fsyntax-only -verify -std=c++1z -fexceptions %s |
| 4 | typedef __SIZE_TYPE__ size_t; |
| 5 | |
| 6 | namespace std { enum class align_val_t : size_t {}; } |
| 7 | |
| 8 | struct S { |
| 9 | // Placement allocation function: |
| 10 | static void* operator new(size_t, size_t); |
| 11 | // Usual (non-placement) deallocation function: |
| 12 | static void operator delete(void*, size_t); // expected-note{{declared here}} |
| 13 | }; |
| 14 | |
| 15 | void testS() { |
| 16 | S* p = new (0) S; // expected-error{{'new' expression with placement arguments refers to non-placement 'operator delete'}} |
| 17 | } |
| 18 | |
| 19 | struct T { |
| 20 | // Placement allocation function: |
| 21 | static void* operator new(size_t, size_t); |
| 22 | // Usual (non-placement) deallocation function: |
| 23 | static void operator delete(void*); |
| 24 | // Placement deallocation function: |
| 25 | static void operator delete(void*, size_t); |
| 26 | }; |
| 27 | |
| 28 | void testT() { |
| 29 | T* p = new (0) T; // ok |
| 30 | } |
| 31 | |
| 32 | #if __cplusplus > 201402L |
| 33 | struct U { |
| 34 | // Placement allocation function: |
| 35 | static void* operator new(size_t, size_t, std::align_val_t); |
| 36 | // Placement deallocation function: |
| 37 | static void operator delete(void*, size_t, std::align_val_t); // expected-note{{declared here}} |
| 38 | }; |
| 39 | |
| 40 | void testU() { |
| 41 | U* p = new (0, std::align_val_t(0)) U; // expected-error{{'new' expression with placement arguments refers to non-placement 'operator delete'}} |
| 42 | } |
| 43 | |
| 44 | struct V { |
| 45 | // Placement allocation function: |
| 46 | static void* operator new(size_t, size_t, std::align_val_t); |
| 47 | // Usual (non-placement) deallocation function: |
| 48 | static void operator delete(void*, std::align_val_t); |
| 49 | // Placement deallocation function: |
| 50 | static void operator delete(void*, size_t, std::align_val_t); |
| 51 | }; |
| 52 | |
| 53 | void testV() { |
| 54 | V* p = new (0, std::align_val_t(0)) V; |
| 55 | } |
| 56 | |
| 57 | struct W { |
| 58 | // Placement allocation function: |
| 59 | static void* operator new(size_t, size_t, std::align_val_t); |
| 60 | // Usual (non-placement) deallocation functions: |
| 61 | static void operator delete(void*); |
| 62 | static void operator delete(void*, size_t, std::align_val_t); // expected-note {{declared here}} |
| 63 | }; |
| 64 | |
| 65 | void testW() { |
| 66 | W* p = new (0, std::align_val_t(0)) W; // expected-error{{'new' expression with placement arguments refers to non-placement 'operator delete'}} |
| 67 | } |
| 68 | #endif |
| 69 | |