Add missing zstd.h to coregrind Makefile.am noinst_HEADERS
[valgrind.git] / memcheck / tests / cxx17_aligned_new.cpp
blob91d4d6535afe43d9dd5a5c519b5c3f8544ac72ae
1 // See
2 // https://en.cppreference.com/w/cpp/memory/new/operator_new
3 // and
4 // https://en.cppreference.com/w/cpp/memory/new/operator_delete
6 // Some of these are only used in very special circumstances
7 // so rather then using new and delete expressions most calls
8 // here directly call the operators
10 #include <cstdlib>
11 #include <new>
12 #include <iostream>
14 class alignas(64) MyClass {
15 public:
16 int i;
19 class OrdinaryClass {
20 public:
21 int i;
24 int main() {
25 // THROWING
26 // plain versions
27 // cppreference new number 1
28 OrdinaryClass* oClass = new OrdinaryClass();
29 // cppreference delete number 1
30 operator delete(oClass);
32 // cppreference new number 2
33 OrdinaryClass* oClass5 = new OrdinaryClass[5];
34 // cppreference delete number 2
35 operator delete[](oClass5);
37 // aligned versions
38 // cppreference new number 3
39 MyClass* myClass = new MyClass();
40 // cppreference delete number 3
41 operator delete(myClass, std::align_val_t(64U));
43 // cppreference new number 4
44 MyClass* myClass5 = new MyClass[5];
45 // cppreference delete number 4
46 operator delete[](myClass5, std::align_val_t(64U));
48 // sized versions
49 oClass = new OrdinaryClass();
50 // cppreference delete number 5
51 operator delete(oClass, sizeof(OrdinaryClass));
53 oClass5 = new OrdinaryClass[5];
54 // cppreference delete number 6
55 operator delete[](oClass5, sizeof(OrdinaryClass)*5);
57 // sized aligned versions
58 myClass = new MyClass();
59 // cppreference delete number 7
60 operator delete(myClass, sizeof(*myClass), std::align_val_t(64U));
62 myClass5 = new MyClass[5];
63 // cppreference delete number 8
64 operator delete [](myClass5, sizeof(*myClass)*5, std::align_val_t(64U));
66 // NOTHROW
68 // cppreference new number 5
69 oClass = new (std::nothrow) OrdinaryClass;
70 delete oClass;
72 // cppreference new number 6
73 oClass5 = new (std::nothrow) OrdinaryClass[5];
74 delete [] oClass5;
76 // cppreference new number 7
77 myClass = new (std::nothrow) MyClass;
78 delete myClass;
80 // cppreference new number 8
81 myClass5 = new (std::nothrow) MyClass[5];
82 delete [] myClass5;