From Jason Turner

[new.delete.single]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp8dhzkahw/{from.md → to.md} +42 -47
tmp/tmp8dhzkahw/{from.md → to.md} RENAMED
@@ -1,48 +1,45 @@
1
  #### Single-object forms <a id="new.delete.single">[[new.delete.single]]</a>
2
 
3
  ``` cpp
4
- void* operator new(std::size_t size);
5
- void* operator new(std::size_t size, std::align_val_t alignment);
6
  ```
7
 
8
- *Effects:* The allocation functions ([[basic.stc.dynamic.allocation]])
9
- called by a *new-expression* ([[expr.new]]) to allocate `size` bytes of
10
  storage. The second form is called for a type with new-extended
11
- alignment, and allocates storage with the specified alignment. The first
12
- form is called otherwise, and allocates storage suitably aligned to
13
- represent any object of that size provided the object’s type does not
14
- have new-extended alignment.
15
 
16
  *Replaceable:* A C++ program may define functions with either of these
17
  function signatures, and thereby displace the default versions defined
18
  by the C++ standard library.
19
 
20
  *Required behavior:* Return a non-null pointer to suitably aligned
21
- storage ([[basic.stc.dynamic]]), or else throw a `bad_alloc` exception.
22
  This requirement is binding on any replacement versions of these
23
  functions.
24
 
25
  *Default behavior:*
26
 
27
  - Executes a loop: Within the loop, the function first attempts to
28
  allocate the requested storage. Whether the attempt involves a call to
29
  the C standard library functions `malloc` or `aligned_alloc` is
30
  unspecified.
31
  - Returns a pointer to the allocated storage if the attempt is
32
- successful. Otherwise, if the current
33
- `new_handler` ([[get.new.handler]]) is a null pointer value, throws
34
- `bad_alloc`.
35
  - Otherwise, the function calls the current `new_handler`
36
- function ([[new.handler]]). If the called function returns, the loop
37
  repeats.
38
  - The loop terminates when an attempt to allocate the requested storage
39
  is successful or when a called `new_handler` function does not return.
40
 
41
  ``` cpp
42
- void* operator new(std::size_t size, const std::nothrow_t&) noexcept;
43
- void* operator new(std::size_t size, std::align_val_t alignment, const std::nothrow_t&) noexcept;
 
44
  ```
45
 
46
  *Effects:* Same as above, except that these are called by a placement
47
  version of a *new-expression* when a C++ program prefers a null pointer
48
  result as an error indication, instead of a `bad_alloc` exception.
@@ -50,11 +47,11 @@ result as an error indication, instead of a `bad_alloc` exception.
50
  *Replaceable:* A C++ program may define functions with either of these
51
  function signatures, and thereby displace the default versions defined
52
  by the C++ standard library.
53
 
54
  *Required behavior:* Return a non-null pointer to suitably aligned
55
- storage ([[basic.stc.dynamic]]), or else return a null pointer. Each of
56
  these nothrow versions of `operator new` returns a pointer obtained as
57
  if acquired from the (possibly replaced) corresponding non-placement
58
  function. This requirement is binding on any replacement versions of
59
  these functions.
60
 
@@ -77,13 +74,13 @@ void operator delete(void* ptr) noexcept;
77
  void operator delete(void* ptr, std::size_t size) noexcept;
78
  void operator delete(void* ptr, std::align_val_t alignment) noexcept;
79
  void operator delete(void* ptr, std::size_t size, std::align_val_t alignment) noexcept;
80
  ```
81
 
82
- *Effects:* The deallocation
83
- functions ([[basic.stc.dynamic.deallocation]]) called by a
84
- *delete-expression* to render the value of `ptr` invalid.
85
 
86
  *Replaceable:* A C++ program may define functions with any of these
87
  function signatures, and thereby displace the default versions defined
88
  by the C++ standard library.
89
 
@@ -94,26 +91,26 @@ define the corresponding version without the `size` parameter.
94
 
95
  [*Note 1*: The default behavior below may change in the future, which
96
  will require replacing both deallocation functions when replacing the
97
  allocation function. — *end note*]
98
 
99
- *Requires:* `ptr` shall be a null pointer or its value shall represent
100
- the address of a block of memory allocated by an earlier call to a
101
- (possibly replaced) `operator new(std::size_t)` or
102
  `operator new(std::size_t, std::align_val_t)` which has not been
103
  invalidated by an intervening call to `operator delete`.
104
 
105
- *Requires:* If an implementation has strict pointer
106
- safety ([[basic.stc.dynamic.safety]]) then `ptr` shall be a
107
- safely-derived pointer.
108
 
109
- *Requires:* If the `alignment` parameter is not present, `ptr` shall
110
- have been returned by an allocation function without an `alignment`
111
- parameter. If present, the `alignment` argument shall equal the
112
- `alignment` argument passed to the allocation function that returned
113
- `ptr`. If present, the `size` argument shall equal the `size` argument
114
- passed to the allocation function that returned `ptr`.
115
 
116
  *Required behavior:* A call to an `operator delete` with a `size`
117
  parameter may be changed to a call to the corresponding
118
  `operator delete` without a `size` parameter, without affecting memory
119
  allocation.
@@ -140,34 +137,32 @@ reclaimed storage will be allocated by subsequent calls to
140
  ``` cpp
141
  void operator delete(void* ptr, const std::nothrow_t&) noexcept;
142
  void operator delete(void* ptr, std::align_val_t alignment, const std::nothrow_t&) noexcept;
143
  ```
144
 
145
- *Effects:* The deallocation
146
- functions ([[basic.stc.dynamic.deallocation]]) called by the
147
- implementation to render the value of `ptr` invalid when the constructor
148
- invoked from a nothrow placement version of the *new-expression* throws
149
- an exception.
150
 
151
  *Replaceable:* A C++ program may define functions with either of these
152
  function signatures, and thereby displace the default versions defined
153
  by the C++ standard library.
154
 
155
- *Requires:* `ptr` shall be a null pointer or its value shall represent
156
- the address of a block of memory allocated by an earlier call to a
157
- (possibly replaced) `operator new(std::size_t)` or
158
  `operator new(std::size_t, std::align_val_t)` which has not been
159
  invalidated by an intervening call to `operator delete`.
160
 
161
- *Requires:* If an implementation has strict pointer
162
- safety ([[basic.stc.dynamic.safety]]) then `ptr` shall be a
163
- safely-derived pointer.
164
 
165
- *Requires:* If the `alignment` parameter is not present, `ptr` shall
166
- have been returned by an allocation function without an `alignment`
167
- parameter. If present, the `alignment` argument shall equal the
168
- `alignment` argument passed to the allocation function that returned
169
- `ptr`.
170
 
171
  *Default behavior:* Calls `operator delete(ptr)`, or
172
  `operator delete(ptr, alignment)`, respectively.
173
 
 
1
  #### Single-object forms <a id="new.delete.single">[[new.delete.single]]</a>
2
 
3
  ``` cpp
4
+ [[nodiscard]] void* operator new(std::size_t size);
5
+ [[nodiscard]] void* operator new(std::size_t size, std::align_val_t alignment);
6
  ```
7
 
8
+ *Effects:* The allocation functions [[basic.stc.dynamic.allocation]]
9
+ called by a *new-expression*[[expr.new]] to allocate `size` bytes of
10
  storage. The second form is called for a type with new-extended
11
+ alignment, and the first form is called otherwise.
 
 
 
12
 
13
  *Replaceable:* A C++ program may define functions with either of these
14
  function signatures, and thereby displace the default versions defined
15
  by the C++ standard library.
16
 
17
  *Required behavior:* Return a non-null pointer to suitably aligned
18
+ storage [[basic.stc.dynamic]], or else throw a `bad_alloc` exception.
19
  This requirement is binding on any replacement versions of these
20
  functions.
21
 
22
  *Default behavior:*
23
 
24
  - Executes a loop: Within the loop, the function first attempts to
25
  allocate the requested storage. Whether the attempt involves a call to
26
  the C standard library functions `malloc` or `aligned_alloc` is
27
  unspecified.
28
  - Returns a pointer to the allocated storage if the attempt is
29
+ successful. Otherwise, if the current `new_handler`
30
+ [[get.new.handler]] is a null pointer value, throws `bad_alloc`.
 
31
  - Otherwise, the function calls the current `new_handler`
32
+ function [[new.handler]]. If the called function returns, the loop
33
  repeats.
34
  - The loop terminates when an attempt to allocate the requested storage
35
  is successful or when a called `new_handler` function does not return.
36
 
37
  ``` cpp
38
+ [[nodiscard]] void* operator new(std::size_t size, const std::nothrow_t&) noexcept;
39
+ [[nodiscard]] void* operator new(std::size_t size, std::align_val_t alignment,
40
+ const std::nothrow_t&) noexcept;
41
  ```
42
 
43
  *Effects:* Same as above, except that these are called by a placement
44
  version of a *new-expression* when a C++ program prefers a null pointer
45
  result as an error indication, instead of a `bad_alloc` exception.
 
47
  *Replaceable:* A C++ program may define functions with either of these
48
  function signatures, and thereby displace the default versions defined
49
  by the C++ standard library.
50
 
51
  *Required behavior:* Return a non-null pointer to suitably aligned
52
+ storage [[basic.stc.dynamic]], or else return a null pointer. Each of
53
  these nothrow versions of `operator new` returns a pointer obtained as
54
  if acquired from the (possibly replaced) corresponding non-placement
55
  function. This requirement is binding on any replacement versions of
56
  these functions.
57
 
 
74
  void operator delete(void* ptr, std::size_t size) noexcept;
75
  void operator delete(void* ptr, std::align_val_t alignment) noexcept;
76
  void operator delete(void* ptr, std::size_t size, std::align_val_t alignment) noexcept;
77
  ```
78
 
79
+ *Effects:* The deallocation functions [[basic.stc.dynamic.deallocation]]
80
+ called by a *delete-expression*[[expr.delete]] to render the value of
81
+ `ptr` invalid.
82
 
83
  *Replaceable:* A C++ program may define functions with any of these
84
  function signatures, and thereby displace the default versions defined
85
  by the C++ standard library.
86
 
 
91
 
92
  [*Note 1*: The default behavior below may change in the future, which
93
  will require replacing both deallocation functions when replacing the
94
  allocation function. — *end note*]
95
 
96
+ *Preconditions:* `ptr` is a null pointer or its value represents the
97
+ address of a block of memory allocated by an earlier call to a (possibly
98
+ replaced) `operator new(std::size_t)` or
99
  `operator new(std::size_t, std::align_val_t)` which has not been
100
  invalidated by an intervening call to `operator delete`.
101
 
102
+ *Preconditions:* If an implementation has strict pointer
103
+ safety [[basic.stc.dynamic.safety]] then `ptr` is a safely-derived
104
+ pointer.
105
 
106
+ *Preconditions:* If the `alignment` parameter is not present, `ptr` was
107
+ returned by an allocation function without an `alignment` parameter. If
108
+ present, the `alignment` argument is equal to the `alignment` argument
109
+ passed to the allocation function that returned `ptr`. If present, the
110
+ `size` argument is equal to the `size` argument passed to the allocation
111
+ function that returned `ptr`.
112
 
113
  *Required behavior:* A call to an `operator delete` with a `size`
114
  parameter may be changed to a call to the corresponding
115
  `operator delete` without a `size` parameter, without affecting memory
116
  allocation.
 
137
  ``` cpp
138
  void operator delete(void* ptr, const std::nothrow_t&) noexcept;
139
  void operator delete(void* ptr, std::align_val_t alignment, const std::nothrow_t&) noexcept;
140
  ```
141
 
142
+ *Effects:* The deallocation functions [[basic.stc.dynamic.deallocation]]
143
+ called by the implementation to render the value of `ptr` invalid when
144
+ the constructor invoked from a nothrow placement version of the
145
+ *new-expression* throws an exception.
 
146
 
147
  *Replaceable:* A C++ program may define functions with either of these
148
  function signatures, and thereby displace the default versions defined
149
  by the C++ standard library.
150
 
151
+ *Preconditions:* `ptr` is a null pointer or its value represents the
152
+ address of a block of memory allocated by an earlier call to a (possibly
153
+ replaced) `operator new(std::size_t)` or
154
  `operator new(std::size_t, std::align_val_t)` which has not been
155
  invalidated by an intervening call to `operator delete`.
156
 
157
+ *Preconditions:* If an implementation has strict pointer
158
+ safety [[basic.stc.dynamic.safety]] then `ptr` is a safely-derived
159
+ pointer.
160
 
161
+ *Preconditions:* If the `alignment` parameter is not present, `ptr` was
162
+ returned by an allocation function without an `alignment` parameter. If
163
+ present, the `alignment` argument is equal to the `alignment` argument
164
+ passed to the allocation function that returned `ptr`.
 
165
 
166
  *Default behavior:* Calls `operator delete(ptr)`, or
167
  `operator delete(ptr, alignment)`, respectively.
168