From Jason Turner

[basic.stc.dynamic]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpyy4ehu7d/{from.md → to.md} +53 -42
tmp/tmpyy4ehu7d/{from.md → to.md} RENAMED
@@ -19,12 +19,14 @@ implicitly declared in global scope in each translation unit of a
19
  program.
20
 
21
  ``` cpp
22
  void* operator new(std::size_t);
23
  void* operator new[](std::size_t);
24
- void operator delete(void*);
25
- void operator delete[](void*);
 
 
26
  ```
27
 
28
  These implicit declarations introduce only the function names `operator`
29
  `new`, `operator` `new[]`, `operator` `delete`, and `operator`
30
  `delete[]`. The implicit declarations do not introduce the names `std`,
@@ -70,64 +72,70 @@ storage allocated (until the storage is explicitly deallocated by a call
70
  to a corresponding deallocation function). Even if the size of the space
71
  requested is zero, the request can fail. If the request succeeds, the
72
  value returned shall be a non-null pointer value ([[conv.ptr]]) `p0`
73
  different from any previously returned value `p1`, unless that value
74
  `p1` was subsequently passed to an `operator` `delete`. The effect of
75
- dereferencing a pointer returned as a request for zero size is
76
- undefined.[^11]
77
 
78
  An allocation function that fails to allocate storage can invoke the
79
  currently installed new-handler function ([[new.handler]]), if any. A
80
  program-supplied allocation function can obtain the address of the
81
  currently installed `new_handler` using the `std::get_new_handler`
82
  function ([[set.new.handler]]). If an allocation function declared with
83
  a non-throwing *exception-specification* ([[except.spec]]) fails to
84
  allocate storage, it shall return a null pointer. Any other allocation
85
  function that fails to allocate storage shall indicate failure only by
86
- throwing an exception of a type that would match a handler (
87
- [[except.handle]]) of type `std::bad_alloc` ([[bad.alloc]]).
88
 
89
  A global allocation function is only called as the result of a new
90
  expression ([[expr.new]]), or called directly using the function call
91
  syntax ([[expr.call]]), or called indirectly through calls to the
92
  functions in the C++standard library. In particular, a global allocation
93
  function is not called to allocate storage for objects with static
94
  storage duration ([[basic.stc.static]]), for objects or references with
95
  thread storage duration ([[basic.stc.thread]]), for objects of type
96
- `std::type_info` ([[expr.typeid]]), or for the copy of an object thrown
97
- by a `throw` expression ([[except.throw]]).
98
 
99
  #### Deallocation functions <a id="basic.stc.dynamic.deallocation">[[basic.stc.dynamic.deallocation]]</a>
100
 
101
  Deallocation functions shall be class member functions or global
102
  functions; a program is ill-formed if deallocation functions are
103
  declared in a namespace scope other than global scope or declared static
104
  in global scope.
105
 
106
  Each deallocation function shall return `void` and its first parameter
107
  shall be `void*`. A deallocation function can have more than one
108
- parameter. If a class `T` has a member deallocation function named
109
- `operator` `delete` with exactly one parameter, then that function is a
110
- usual (non-placement) deallocation function. If class `T` does not
111
- declare such an `operator` `delete` but does declare a member
112
- deallocation function named `operator` `delete` with exactly two
113
- parameters, the second of which has type `std::size_t` (
114
- [[support.types]]), then this function is a usual deallocation function.
115
- Similarly, if a class `T` has a member deallocation function named
116
- `operator` `delete[]` with exactly one parameter, then that function is
117
- a usual (non-placement) deallocation function. If class `T` does not
118
- declare such an `operator` `delete[]` but does declare a member
119
- deallocation function named `operator` `delete[]` with exactly two
120
- parameters, the second of which has type `std::size_t`, then this
121
- function is a usual deallocation function. A deallocation function can
122
- be an instance of a function template. Neither the first parameter nor
123
- the return type shall depend on a template parameter. That is, a
124
- deallocation function template shall have a first parameter of type
125
- `void*` and a return type of `void` (as specified above). A deallocation
126
- function template shall have two or more function parameters. A template
127
- instance is never a usual deallocation function, regardless of its
128
- signature.
 
 
 
 
 
 
129
 
130
  If a deallocation function terminates by throwing an exception, the
131
  behavior is undefined. The value of the first argument supplied to a
132
  deallocation function may be a null pointer value; if so, and if the
133
  deallocation function is one supplied in the standard library, the call
@@ -143,31 +151,34 @@ invocation of either `operator` `new[](std::size_t)` or `operator`
143
 
144
  If the argument given to a deallocation function in the standard library
145
  is a pointer that is not the null pointer value ([[conv.ptr]]), the
146
  deallocation function shall deallocate the storage referenced by the
147
  pointer, rendering invalid all pointers referring to any part of the
148
- *deallocated storage*. The effect of using an invalid pointer value
149
- (including passing it to a deallocation function) is undefined.[^12]
 
 
150
 
151
  #### Safely-derived pointers <a id="basic.stc.dynamic.safety">[[basic.stc.dynamic.safety]]</a>
152
 
153
  A *traceable pointer object* is
154
 
155
  - an object of an object pointer type ([[basic.compound]]), or
156
  - an object of an integral type that is at least as large as
157
  `std::intptr_t`, or
158
- - a sequence of elements in an array of character type, where the size
159
- and alignment of the sequence match those of some object pointer type.
 
160
 
161
  A pointer value is a *safely-derived pointer* to a dynamic object only
162
  if it has an object pointer type and it is one of the following:
163
 
164
  - the value returned by a call to the C++standard library implementation
165
- of `::operator new(std::size_t)`;[^13]
166
  - the result of taking the address of an object (or one of its
167
- subobjects) designated by an lvalue resulting from dereferencing a
168
- safely-derived pointer value;
169
  - the result of well-defined pointer arithmetic ([[expr.add]]) using a
170
  safely-derived pointer value;
171
  - the result of a well-defined pointer conversion ([[conv.ptr]], 
172
  [[expr.cast]]) of a safely-derived pointer value;
173
  - the result of a `reinterpret_cast` of a safely-derived pointer value;
@@ -194,16 +205,16 @@ at least as large as `std::intptr_t` and it is one of the following:
194
  `reinterpret_cast<void*>(P)`.
195
 
196
  An implementation may have *relaxed pointer safety*, in which case the
197
  validity of a pointer value does not depend on whether it is a
198
  safely-derived pointer value. Alternatively, an implementation may have
199
- *strict pointer safety*, in which case a pointer value that is not a
200
- safely-derived pointer value is an invalid pointer value unless the
201
- referenced complete object is of dynamic storage duration and has
202
- previously been declared reachable ([[util.dynamic.safety]]). the
203
- effect of using an invalid pointer value (including passing it to a
204
- deallocation function) is undefined, see 
205
  [[basic.stc.dynamic.deallocation]]. This is true even if the
206
  unsafely-derived pointer value might compare equal to some
207
  safely-derived pointer value. It is implementation defined whether an
208
  implementation has relaxed or strict pointer safety.
209
 
 
19
  program.
20
 
21
  ``` cpp
22
  void* operator new(std::size_t);
23
  void* operator new[](std::size_t);
24
+ void operator delete(void*) noexcept;
25
+ void operator delete[](void*) noexcept;
26
+ void operator delete(void*, std::size_t) noexcept;
27
+ void operator delete[](void*, std::size_t) noexcept;
28
  ```
29
 
30
  These implicit declarations introduce only the function names `operator`
31
  `new`, `operator` `new[]`, `operator` `delete`, and `operator`
32
  `delete[]`. The implicit declarations do not introduce the names `std`,
 
72
  to a corresponding deallocation function). Even if the size of the space
73
  requested is zero, the request can fail. If the request succeeds, the
74
  value returned shall be a non-null pointer value ([[conv.ptr]]) `p0`
75
  different from any previously returned value `p1`, unless that value
76
  `p1` was subsequently passed to an `operator` `delete`. The effect of
77
+ indirecting through a pointer returned as a request for zero size is
78
+ undefined.[^12]
79
 
80
  An allocation function that fails to allocate storage can invoke the
81
  currently installed new-handler function ([[new.handler]]), if any. A
82
  program-supplied allocation function can obtain the address of the
83
  currently installed `new_handler` using the `std::get_new_handler`
84
  function ([[set.new.handler]]). If an allocation function declared with
85
  a non-throwing *exception-specification* ([[except.spec]]) fails to
86
  allocate storage, it shall return a null pointer. Any other allocation
87
  function that fails to allocate storage shall indicate failure only by
88
+ throwing an exception ([[except.throw]]) of a type that would match a
89
+ handler ([[except.handle]]) of type `std::bad_alloc` ([[bad.alloc]]).
90
 
91
  A global allocation function is only called as the result of a new
92
  expression ([[expr.new]]), or called directly using the function call
93
  syntax ([[expr.call]]), or called indirectly through calls to the
94
  functions in the C++standard library. In particular, a global allocation
95
  function is not called to allocate storage for objects with static
96
  storage duration ([[basic.stc.static]]), for objects or references with
97
  thread storage duration ([[basic.stc.thread]]), for objects of type
98
+ `std::type_info` ([[expr.typeid]]), or for an exception object (
99
+ [[except.throw]]).
100
 
101
  #### Deallocation functions <a id="basic.stc.dynamic.deallocation">[[basic.stc.dynamic.deallocation]]</a>
102
 
103
  Deallocation functions shall be class member functions or global
104
  functions; a program is ill-formed if deallocation functions are
105
  declared in a namespace scope other than global scope or declared static
106
  in global scope.
107
 
108
  Each deallocation function shall return `void` and its first parameter
109
  shall be `void*`. A deallocation function can have more than one
110
+ parameter. The global `operator delete` with exactly one parameter is a
111
+ usual (non-placement) deallocation function. The global
112
+ `operator delete` with exactly two parameters, the second of which has
113
+ type `std::size_t`, is a usual deallocation function. Similarly, the
114
+ global `operator delete[]` with exactly one parameter is a usual
115
+ deallocation function. The global `operator delete[]` with exactly two
116
+ parameters, the second of which has type `std::size_t`, is a usual
117
+ deallocation function.[^13] If a class `T` has a member deallocation
118
+ function named `operator` `delete` with exactly one parameter, then that
119
+ function is a usual deallocation function. If class `T` does not declare
120
+ such an `operator` `delete` but does declare a member deallocation
121
+ function named `operator` `delete` with exactly two parameters, the
122
+ second of which has type `std::size_t`, then this function is a usual
123
+ deallocation function. Similarly, if a class `T` has a member
124
+ deallocation function named `operator` `delete[]` with exactly one
125
+ parameter, then that function is a usual (non-placement) deallocation
126
+ function. If class `T` does not declare such an `operator` `delete[]`
127
+ but does declare a member deallocation function named `operator`
128
+ `delete[]` with exactly two parameters, the second of which has type
129
+ `std::size_t`, then this function is a usual deallocation function. A
130
+ deallocation function can be an instance of a function template. Neither
131
+ the first parameter nor the return type shall depend on a template
132
+ parameter. That is, a deallocation function template shall have a first
133
+ parameter of type `void*` and a return type of `void` (as specified
134
+ above). A deallocation function template shall have two or more function
135
+ parameters. A template instance is never a usual deallocation function,
136
+ regardless of its signature.
137
 
138
  If a deallocation function terminates by throwing an exception, the
139
  behavior is undefined. The value of the first argument supplied to a
140
  deallocation function may be a null pointer value; if so, and if the
141
  deallocation function is one supplied in the standard library, the call
 
151
 
152
  If the argument given to a deallocation function in the standard library
153
  is a pointer that is not the null pointer value ([[conv.ptr]]), the
154
  deallocation function shall deallocate the storage referenced by the
155
  pointer, rendering invalid all pointers referring to any part of the
156
+ deallocated storage. Indirection through an invalid pointer value and
157
+ passing an invalid pointer value to a deallocation function have
158
+ undefined behavior. Any other use of an invalid pointer value has
159
+ implementation-defined behavior.[^14]
160
 
161
  #### Safely-derived pointers <a id="basic.stc.dynamic.safety">[[basic.stc.dynamic.safety]]</a>
162
 
163
  A *traceable pointer object* is
164
 
165
  - an object of an object pointer type ([[basic.compound]]), or
166
  - an object of an integral type that is at least as large as
167
  `std::intptr_t`, or
168
+ - a sequence of elements in an array of narrow character type (
169
+ [[basic.fundamental]]), where the size and alignment of the sequence
170
+ match those of some object pointer type.
171
 
172
  A pointer value is a *safely-derived pointer* to a dynamic object only
173
  if it has an object pointer type and it is one of the following:
174
 
175
  - the value returned by a call to the C++standard library implementation
176
+ of `::operator new(std::size_t)`;[^15]
177
  - the result of taking the address of an object (or one of its
178
+ subobjects) designated by an lvalue resulting from indirection through
179
+ a safely-derived pointer value;
180
  - the result of well-defined pointer arithmetic ([[expr.add]]) using a
181
  safely-derived pointer value;
182
  - the result of a well-defined pointer conversion ([[conv.ptr]], 
183
  [[expr.cast]]) of a safely-derived pointer value;
184
  - the result of a `reinterpret_cast` of a safely-derived pointer value;
 
205
  `reinterpret_cast<void*>(P)`.
206
 
207
  An implementation may have *relaxed pointer safety*, in which case the
208
  validity of a pointer value does not depend on whether it is a
209
  safely-derived pointer value. Alternatively, an implementation may have
210
+ *strict pointer safety*, in which case a pointer value referring to an
211
+ object with dynamic storage duration that is not a safely-derived
212
+ pointer value is an invalid pointer value unless the referenced complete
213
+ object has previously been declared reachable (
214
+ [[util.dynamic.safety]]). the effect of using an invalid pointer value
215
+ (including passing it to a deallocation function) is undefined, see 
216
  [[basic.stc.dynamic.deallocation]]. This is true even if the
217
  unsafely-derived pointer value might compare equal to some
218
  safely-derived pointer value. It is implementation defined whether an
219
  implementation has relaxed or strict pointer safety.
220