| 1 |
// RUN: %check_clang_tidy %s -std=c++14 cert-mem57-cpp %t |
| 2 |
|
| 3 |
namespace std { |
| 4 |
typedef __typeof(sizeof(int)) size_t; |
| 5 |
void *aligned_alloc(size_t, size_t); |
| 6 |
void free(void *); |
| 7 |
} // namespace std |
| 8 |
|
| 9 |
struct alignas(128) Vector1 { |
| 10 |
char elems[128]; |
| 11 |
}; |
| 12 |
|
| 13 |
struct Vector2 { |
| 14 |
char elems[128]; |
| 15 |
}; |
| 16 |
|
| 17 |
struct alignas(128) Vector3 { |
| 18 |
char elems[128]; |
| 19 |
static void *operator new(std::size_t nbytes) noexcept(true) { |
| 20 |
return std::aligned_alloc(alignof(Vector3), nbytes); |
| 21 |
} |
| 22 |
static void operator delete(void *p) { |
| 23 |
std::free(p); |
| 24 |
} |
| 25 |
}; |
| 26 |
|
| 27 |
struct alignas(8) Vector4 { |
| 28 |
char elems[32]; |
| 29 |
}; |
| 30 |
|
| 31 |
void f() { |
| 32 |
auto *V1 = new Vector1; |
| 33 |
// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: allocation function returns a pointer with alignment {{[0-9]+}} but the over-aligned type being allocated requires alignment 128 [cert-mem57-cpp] |
| 34 |
auto *V2 = new Vector2; |
| 35 |
auto *V3 = new Vector3; |
| 36 |
auto *V4 = new Vector4; |
| 37 |
auto *V1_Arr = new Vector1[2]; |
| 38 |
// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: allocation function returns a pointer with alignment {{[0-9]+}} but the over-aligned type being allocated requires alignment 128 [cert-mem57-cpp] |
| 39 |
} |