1// RUN: %check_clang_tidy %s -std=c++14 cert-mem57-cpp %t
2
3namespace std {
4typedef __typeof(sizeof(int)) size_t;
5void *aligned_alloc(size_t, size_t);
6void free(void *);
7} // namespace std
8
9struct alignas(128) Vector1 {
10 char elems[128];
11};
12
13struct Vector2 {
14 char elems[128];
15};
16
17struct 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
27struct alignas(8) Vector4 {
28 char elems[32];
29};
30
31void 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}
40

source code of clang-tools-extra/test/clang-tidy/checkers/cert/mem57-cpp.cpp