Aaron Ballman | de34985 | 2015-09-29 13:12:21 +0000 | [diff] [blame^] | 1 | // RUN: %python %S/check_clang_tidy.py %s misc-new-delete-overloads %t -- -std=c++14 |
| 2 | |
| 3 | struct S { |
| 4 | // CHECK-MESSAGES: :[[@LINE+1]]:9: warning: declaration of 'operator new' has no matching declaration of 'operator delete' at the same scope [misc-new-delete-overloads] |
| 5 | void *operator new(size_t size) noexcept; |
| 6 | // CHECK-MESSAGES: :[[@LINE+1]]:9: warning: declaration of 'operator new[]' has no matching declaration of 'operator delete[]' at the same scope |
| 7 | void *operator new[](size_t size) noexcept; |
| 8 | }; |
| 9 | |
| 10 | // CHECK-MESSAGES: :[[@LINE+1]]:7: warning: declaration of 'operator new' has no matching declaration of 'operator delete' at the same scope |
| 11 | void *operator new(size_t size) noexcept; |
| 12 | |
| 13 | struct T { |
| 14 | // Sized deallocations are not enabled by default, and so this new/delete pair |
| 15 | // does not match. However, we expect only one warning, for the new, because |
| 16 | // the operator delete is a placement delete and we do not warn on mismatching |
| 17 | // placement operations. |
| 18 | // CHECK-MESSAGES: :[[@LINE+1]]:9: warning: declaration of 'operator new' has no matching declaration of 'operator delete' at the same scope |
| 19 | void *operator new(size_t size) noexcept; |
| 20 | void operator delete(void *ptr, size_t) noexcept; // ok only if sized deallocation is enabled |
| 21 | }; |
| 22 | |
| 23 | struct U { |
| 24 | void *operator new(size_t size) noexcept; |
| 25 | void operator delete(void *ptr) noexcept; |
| 26 | |
| 27 | void *operator new[](size_t) noexcept; |
| 28 | void operator delete[](void *) noexcept; |
| 29 | }; |
| 30 | |
| 31 | struct Z { |
| 32 | // CHECK-MESSAGES: :[[@LINE+1]]:8: warning: declaration of 'operator delete' has no matching declaration of 'operator new' at the same scope |
| 33 | void operator delete(void *ptr) noexcept; |
| 34 | // CHECK-MESSAGES: :[[@LINE+1]]:8: warning: declaration of 'operator delete[]' has no matching declaration of 'operator new[]' at the same scope |
| 35 | void operator delete[](void *ptr) noexcept; |
| 36 | }; |
| 37 | |
| 38 | struct A { |
| 39 | void *operator new(size_t size, Z) noexcept; // ok, placement new |
| 40 | }; |
| 41 | |
| 42 | struct B { |
| 43 | void operator delete(void *ptr, A) noexcept; // ok, placement delete |
| 44 | }; |
| 45 | |
| 46 | // It is okay to have a class with an inaccessible free store operator. |
| 47 | struct C { |
| 48 | void *operator new(size_t, A) noexcept; // ok, placement new |
| 49 | private: |
| 50 | void operator delete(void *) noexcept; |
| 51 | }; |
| 52 | |
| 53 | // It is also okay to have a class with a delete free store operator. |
| 54 | struct D { |
| 55 | void *operator new(size_t, A) noexcept; // ok, placement new |
| 56 | void operator delete(void *) noexcept = delete; |
| 57 | }; |
| 58 | |
| 59 | struct E : U { |
| 60 | void *operator new(size_t) noexcept; // okay, we inherit operator delete from U |
| 61 | }; |
| 62 | |
| 63 | struct F : S { |
| 64 | // CHECK-MESSAGES: :[[@LINE+1]]:9: warning: declaration of 'operator new' has no matching declaration of 'operator delete' at the same scope |
| 65 | void *operator new(size_t) noexcept; |
| 66 | }; |
| 67 | |
| 68 | class G { |
| 69 | void operator delete(void *) noexcept; |
| 70 | }; |
| 71 | |
| 72 | struct H : G { |
| 73 | // CHECK-MESSAGES: :[[@LINE+1]]:9: warning: declaration of 'operator new' has no matching declaration of 'operator delete' at the same scope |
| 74 | void *operator new(size_t) noexcept; // base class operator is inaccessible |
| 75 | }; |