From Jason Turner

[basic.stc.dynamic.allocation]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp42bvnw2q/{from.md → to.md} +56 -48
tmp/tmp42bvnw2q/{from.md → to.md} RENAMED
@@ -1,63 +1,71 @@
1
- #### Allocation functions <a id="basic.stc.dynamic.allocation">[[basic.stc.dynamic.allocation]]</a>
2
 
3
  An allocation function shall be a class member function or a global
4
  function; a program is ill-formed if an allocation function is declared
5
  in a namespace scope other than global scope or declared static in
6
  global scope. The return type shall be `void*`. The first parameter
7
- shall have type `std::size_t` ([[support.types]]). The first parameter
8
- shall not have an associated default argument ([[dcl.fct.default]]).
9
- The value of the first parameter shall be interpreted as the requested
10
- size of the allocation. An allocation function can be a function
11
- template. Such a template shall declare its return type and first
12
- parameter as specified above (that is, template parameter types shall
13
- not be used in the return type and first parameter type). Template
14
- allocation functions shall have two or more parameters.
15
 
16
- The allocation function attempts to allocate the requested amount of
17
- storage. If it is successful, it shall return the address of the start
18
- of a block of storage whose length in bytes shall be at least as large
19
- as the requested size. There are no constraints on the contents of the
20
- allocated storage on return from the allocation function. The order,
21
- contiguity, and initial value of storage allocated by successive calls
22
- to an allocation function are unspecified. The pointer returned shall be
23
- suitably aligned so that it can be converted to a pointer to any
24
- suitable complete object type ([[new.delete.single]]) and then used to
25
- access the object or array in the storage allocated (until the storage
26
- is explicitly deallocated by a call to a corresponding deallocation
27
- function). Even if the size of the space requested is zero, the request
28
- can fail. If the request succeeds, the value returned shall be a
29
- non-null pointer value ([[conv.ptr]]) `p0` different from any
30
- previously returned value `p1`, unless that value `p1` was subsequently
31
- passed to an `operator` `delete`. Furthermore, for the library
32
- allocation functions in  [[new.delete.single]] and 
33
- [[new.delete.array]], `p0` shall represent the address of a block of
34
- storage disjoint from the storage for any other object accessible to the
35
- caller. The effect of indirecting through a pointer returned as a
36
- request for zero size is undefined.[^13]
 
 
 
 
 
 
 
37
 
38
  An allocation function that fails to allocate storage can invoke the
39
- currently installed new-handler function ([[new.handler]]), if any.
40
 
41
- [*Note 1*: A program-supplied allocation function can obtain the
42
  address of the currently installed `new_handler` using the
43
- `std::get_new_handler` function ([[set.new.handler]]). — *end note*]
44
 
45
- If an allocation function that has a non-throwing exception
46
- specification ([[except.spec]]) fails to allocate storage, it shall
47
- return a null pointer. Any other allocation function that fails to
48
- allocate storage shall indicate failure only by throwing an exception (
49
- [[except.throw]]) of a type that would match a handler (
50
- [[except.handle]]) of type `std::bad_alloc` ([[bad.alloc]]).
51
 
52
  A global allocation function is only called as the result of a new
53
- expression ([[expr.new]]), or called directly using the function call
54
- syntax ([[expr.call]]), or called indirectly through calls to the
55
- functions in the C++standard library.
 
56
 
57
- [*Note 2*: In particular, a global allocation function is not called to
58
- allocate storage for objects with static storage duration (
59
- [[basic.stc.static]]), for objects or references with thread storage
60
- duration ([[basic.stc.thread]]), for objects of type `std::type_info` (
61
- [[expr.typeid]]), or for an exception object (
62
- [[except.throw]]). — *end note*]
63
 
 
1
+ ##### Allocation functions <a id="basic.stc.dynamic.allocation">[[basic.stc.dynamic.allocation]]</a>
2
 
3
  An allocation function shall be a class member function or a global
4
  function; a program is ill-formed if an allocation function is declared
5
  in a namespace scope other than global scope or declared static in
6
  global scope. The return type shall be `void*`. The first parameter
7
+ shall have type `std::size_t` [[support.types]]. The first parameter
8
+ shall not have an associated default argument [[dcl.fct.default]]. The
9
+ value of the first parameter is interpreted as the requested size of the
10
+ allocation. An allocation function can be a function template. Such a
11
+ template shall declare its return type and first parameter as specified
12
+ above (that is, template parameter types shall not be used in the return
13
+ type and first parameter type). Template allocation functions shall have
14
+ two or more parameters.
15
 
16
+ An allocation function attempts to allocate the requested amount of
17
+ storage. If it is successful, it returns the address of the start of a
18
+ block of storage whose length in bytes is at least as large as the
19
+ requested size. The order, contiguity, and initial value of storage
20
+ allocated by successive calls to an allocation function are unspecified.
21
+ Even if the size of the space requested is zero, the request can fail.
22
+ If the request succeeds, the value returned by a replaceable allocation
23
+ function is a non-null pointer value [[basic.compound]] `p0` different
24
+ from any previously returned value `p1`, unless that value `p1` was
25
+ subsequently passed to a replaceable deallocation function. Furthermore,
26
+ for the library allocation functions in  [[new.delete.single]] and 
27
+ [[new.delete.array]], `p0` represents the address of a block of storage
28
+ disjoint from the storage for any other object accessible to the caller.
29
+ The effect of indirecting through a pointer returned from a request for
30
+ zero size is undefined.[^14]
31
+
32
+ For an allocation function other than a reserved placement allocation
33
+ function [[new.delete.placement]], the pointer returned on a successful
34
+ call shall represent the address of storage that is aligned as follows:
35
+
36
+ - If the allocation function takes an argument of type
37
+ `std::align_val_t`, the storage will have the alignment specified by
38
+ the value of this argument.
39
+ - Otherwise, if the allocation function is named `operator new[]`, the
40
+ storage is aligned for any object that does not have new-extended
41
+ alignment [[basic.align]] and is no larger than the requested size.
42
+ - Otherwise, the storage is aligned for any object that does not have
43
+ new-extended alignment and is of the requested size.
44
 
45
  An allocation function that fails to allocate storage can invoke the
46
+ currently installed new-handler function [[new.handler]], if any.
47
 
48
+ [*Note 3*: A program-supplied allocation function can obtain the
49
  address of the currently installed `new_handler` using the
50
+ `std::get_new_handler` function [[get.new.handler]]. — *end note*]
51
 
52
+ An allocation function that has a non-throwing exception specification
53
+ [[except.spec]] indicates failure by returning a null pointer value. Any
54
+ other allocation function never returns a null pointer value and
55
+ indicates failure only by throwing an exception [[except.throw]] of a
56
+ type that would match a handler [[except.handle]] of type
57
+ `std::bad_alloc` [[bad.alloc]].
58
 
59
  A global allocation function is only called as the result of a new
60
+ expression [[expr.new]], or called directly using the function call
61
+ syntax [[expr.call]], or called indirectly to allocate storage for a
62
+ coroutine state [[dcl.fct.def.coroutine]], or called indirectly through
63
+ calls to the functions in the C++ standard library.
64
 
65
+ [*Note 4*: In particular, a global allocation function is not called to
66
+ allocate storage for objects with static storage duration
67
+ [[basic.stc.static]], for objects or references with thread storage
68
+ duration [[basic.stc.thread]], for objects of type `std::type_info`
69
+ [[expr.typeid]], or for an exception object
70
+ [[except.throw]]. — *end note*]
71