Стандарт C++ 11 (1119564), страница 23
Текст из файла (страница 23)
[ Note: A program-supplied allocation function can obtain the address of the currentlyinstalled new_handler using the std::get_new_handler function (18.6.2.4). — end note ] If an allocationfunction declared with a non-throwing exception-specification (15.4) fails to allocate storage, it shall returna null pointer. Any other allocation function that fails to allocate storage shall indicate failure only bythrowing an exception of a type that would match a handler (15.3) of type std::bad_alloc (18.6.2.1).4A global allocation function is only called as the result of a new expression (5.3.4), or called directly using thefunction call syntax (5.2.2), or called indirectly through calls to the functions in the C++ standard library.[ Note: In particular, a global allocation function is not called to allocate storage for objects with staticstorage duration (3.7.1), for objects or references with thread storage duration (3.7.2), for objects of typestd::type_info (5.2.8), or for the copy of an object thrown by a throw expression (15.1).
— end note ]3.7.4.21Deallocation functions[basic.stc.dynamic.deallocation]Deallocation functions shall be class member functions or global functions; a program is ill-formed if deallocation functions are declared in a namespace scope other than global scope or declared static in globalscope.35) The intent is to have operator new() implementable by calling std::malloc() or std::calloc(), so the rules are substantially the same.
C++ differs from C in requiring a zero request to return a non-null pointer.§ 3.7.4.2© ISO/IEC 2011 – All rights reserved67ISO/IEC 14882:2011(E)2Each deallocation function shall return void and its first parameter shall be void*. A deallocation functioncan have more than one parameter. If a class T has a member deallocation function named operator deletewith exactly one parameter, then that function is a usual (non-placement) deallocation function.
If class Tdoes not declare such an operator delete but does declare a member deallocation function named operatordelete with exactly two parameters, the second of which has type std::size_t (18.2), then this functionis a usual deallocation function. Similarly, if a class T has a member deallocation function named operatordelete[] with exactly one parameter, then that function is a usual (non-placement) deallocation function.If class T does not declare such an operator delete[] but does declare a member deallocation functionnamed operator delete[] with exactly two parameters, the second of which has type std::size_t, thenthis function is a usual deallocation function.
A deallocation function can be an instance of a functiontemplate. Neither the first parameter nor the return type shall depend on a template parameter. [ Note:That is, a deallocation function template shall have a first parameter of type void* and a return type ofvoid (as specified above). — end note ] A deallocation function template shall have two or more functionparameters. A template instance is never a usual deallocation function, regardless of its signature.3If a deallocation function terminates by throwing an exception, the behavior is undefined. The value of thefirst argument supplied to a deallocation function may be a null pointer value; if so, and if the deallocationfunction is one supplied in the standard library, the call has no effect. Otherwise, the behavior is undefinedif the value supplied to operator delete(void*) in the standard library is not one of the values returnedby a previous invocation of either operator new(std::size_t) or operator new(std::size_t, conststd::nothrow_t&) in the standard library, and the behavior is undefined if the value supplied to operatordelete[](void*) in the standard library is not one of the values returned by a previous invocation ofeither operator new[](std::size_t) or operator new[](std::size_t, const std::nothrow_t&) in thestandard library.4If the argument given to a deallocation function in the standard library is a pointer that is not the null pointervalue (4.10), the deallocation function shall deallocate the storage referenced by the pointer, rendering invalidall pointers referring to any part of the deallocated storage.
The effect of using an invalid pointer value(including passing it to a deallocation function) is undefined.363.7.4.31Safely-derived pointers[basic.stc.dynamic.safety]A traceable pointer object is— an object of an object pointer type (3.9.2), or— an object of an integral type that is at least as large as std::intptr_t, or— a sequence of elements in an array of character type, where the size and alignment of the sequencematch those of some object pointer type.2A pointer value is a safely-derived pointer to a dynamic object only if it has an object pointer type and itis one of the following:— the value returned by a call to the C++ standard library implementation of ::operator new(std::size_t);37— the result of taking the address of an object (or one of its subobjects) designated by an lvalue resultingfrom dereferencing a safely-derived pointer value;— the result of well-defined pointer arithmetic (5.7) using a safely-derived pointer value;36) On some implementations, it causes a system-generated runtime fault.37) This section does not impose restrictions on dereferencing pointers to memory not allocated by ::operator new.
Thismaintains the ability of many C++ implementations to use binary libraries and components written in other languages. Inparticular, this applies to C binaries, because dereferencing pointers to memory allocated by malloc is not restricted.§ 3.7.4.368© ISO/IEC 2011 – All rights reservedISO/IEC 14882:2011(E)— the result of a well-defined pointer conversion (4.10, 5.4) of a safely-derived pointer value;— the result of a reinterpret_cast of a safely-derived pointer value;— the result of a reinterpret_cast of an integer representation of a safely-derived pointer value;— the value of an object whose value was copied from a traceable pointer object, where at the time ofthe copy the source object contained a copy of a safely-derived pointer value.3An integer value is an integer representation of a safely-derived pointer only if its type is at least as large asstd::intptr_t and it is one of the following:— the result of a reinterpret_cast of a safely-derived pointer value;— the result of a valid conversion of an integer representation of a safely-derived pointer value;— the value of an object whose value was copied from a traceable pointer object, where at the time ofthe copy the source object contained an integer representation of a safely-derived pointer value;— the result of an additive or bitwise operation, one of whose operands is an integer representation of asafely-derived pointer value P, if that result converted by reinterpret_cast<void*> would compareequal to a safely-derived pointer computable from reinterpret_cast<void*>(P).4An implementation may have relaxed pointer safety, in which case the validity of a pointer value does notdepend on whether it is a safely-derived pointer value.
Alternatively, an implementation may have strictpointer safety, in which case a pointer value that is not a safely-derived pointer value is an invalid pointervalue unless the referenced complete object is of dynamic storage duration and has previously been declaredreachable (20.6.4). [ Note: the effect of using an invalid pointer value (including passing it to a deallocationfunction) is undefined, see 3.7.4.2. This is true even if the unsafely-derived pointer value might compare equalto some safely-derived pointer value.
— end note ] It is implementation defined whether an implementationhas relaxed or strict pointer safety.3.7.51[basic.stc.inherit]The storage duration of member subobjects, base class subobjects and array elements is that of their completeobject (1.8).3.81Duration of subobjectsObject lifetime[basic.life]The lifetime of an object is a runtime property of the object. An object is said to have non-trivial initializationif it is of a class or aggregate type and it or one of its members is initialized by a constructor other than a trivialdefault constructor. [ Note: initialization by a trivial copy/move constructor is non-trivial initialization.