Стандарт C++ 11 (1119564), страница 39
Текст из файла (страница 39)
If the copy is elided in one place, it need not be elided in the other.5.3.51Delete[expr.delete]The delete-expression operator destroys a most derived object (1.8) or array created by a new-expression.delete-expression:::opt delete cast-expression::opt delete [ ] cast-expressionThe first alternative is for non-array objects, and the second is for arrays. Whenever the delete keyword is immediately followed by empty square brackets, it shall be interpreted as the second alternative.77The operand shall have a pointer to object type, or a class type having a single non-explicit conversionfunction (12.3.2) to a pointer to object type.
The result has type void.782If the operand has a class type, the operand is converted to a pointer type by calling the above-mentionedconversion function, and the converted operand is used in place of the original operand for the remainder ofthis section. In the first alternative (delete object), the value of the operand of delete may be a null pointervalue, a pointer to a non-array object created by a previous new-expression, or a pointer to a subobject (1.8)representing a base class of such an object (Clause 10). If not, the behavior is undefined. In the second77) A lambda expression with a lambda-introducer that consists of empty square brackets can follow the delete keyword ifthe lambda expression is enclosed in parentheses.78) This implies that an object cannot be deleted using a pointer of type void* because void is not an object type.§ 5.3.5© ISO/IEC 2011 – All rights reserved115ISO/IEC 14882:2011(E)alternative (delete array), the value of the operand of delete may be a null pointer value or a pointervalue that resulted from a previous array new-expression.79 If not, the behavior is undefined.
[ Note: thismeans that the syntax of the delete-expression must match the type of the object allocated by new, notthe syntax of the new-expression. — end note ] [ Note: a pointer to a const type can be the operand of adelete-expression; it is not necessary to cast away the constness (5.2.11) of the pointer expression before itis used as the operand of the delete-expression.
— end note ]3In the first alternative (delete object), if the static type of the object to be deleted is different from itsdynamic type, the static type shall be a base class of the dynamic type of the object to be deleted and thestatic type shall have a virtual destructor or the behavior is undefined. In the second alternative (deletearray) if the dynamic type of the object to be deleted differs from its static type, the behavior is undefined.4The cast-expression in a delete-expression shall be evaluated exactly once.5If the object being deleted has incomplete class type at the point of deletion and the complete class has anon-trivial destructor or a deallocation function, the behavior is undefined.6If the value of the operand of the delete-expression is not a null pointer value, the delete-expression willinvoke the destructor (if any) for the object or the elements of the array being deleted. In the case of anarray, the elements will be destroyed in order of decreasing address (that is, in reverse order of the completionof their constructor; see 12.6.2).7If the value of the operand of the delete-expression is not a null pointer value, the delete-expression willcall a deallocation function (3.7.4.2).
Otherwise, it is unspecified whether the deallocation function will becalled. [ Note: The deallocation function is called regardless of whether the destructor for the object or someelement of the array throws an exception. — end note ]8[ Note: An implementation provides default definitions of the global deallocation functions operator delete()for non-arrays (18.6.1.1) and operator delete[]() for arrays (18.6.1.2). A C++ program can provide alternative definitions of these functions (17.6.4.6), and/or class-specific versions (12.5). — end note ]9When the keyword delete in a delete-expression is preceded by the unary :: operator, the global deallocation function is used to deallocate the storage.10Access and ambiguity control are done for both the deallocation function and the destructor (12.4, 12.5).5.3.6Alignof[expr.alignof ]1An alignof expression yields the alignment requirement of its operand type.
The operand shall be a type-idrepresenting a complete object type or an array thereof or a reference to a complete object type.2The result is an integral constant of type std::size_t.3When alignof is applied to a reference type, the result shall be the alignment of the referenced type. Whenalignof is applied to an array type, the result shall be the alignment of the element type.5.3.71noexcept operator[expr.unary.noexcept]The noexcept operator determines whether the evaluation of its operand, which is an unevaluated operand(Clause 5), can throw an exception (15.1).noexcept-expression:noexcept ( expression )2The result of the noexcept operator is a constant of type bool and is an rvalue.79) For non-zero-length arrays, this is the same as a pointer to the first element of the array created by that new-expression.Zero-length arrays do not have a first element.§ 5.3.7116© ISO/IEC 2011 – All rights reservedISO/IEC 14882:2011(E)3The result of the noexcept operator is false if in a potentially-evaluated context the expression wouldcontain— a potentially evaluated call80 to a function, member function, function pointer, or member functionpointer that does not have a non-throwing exception-specification (15.4), unless the call is a constantexpression (5.19),— a potentially evaluated throw-expression (15.1),— a potentially evaluated dynamic_cast expression dynamic_cast<T>(v), where T is a reference type,that requires a run-time check (5.2.7), or— a potentially evaluated typeid expression (5.2.8) applied to a glvalue expression whose type is apolymorphic class type (10.3).Otherwise, the result is true.5.4Explicit type conversion (cast notation)[expr.cast]1The result of the expression (T) cast-expression is of type T.
The result is an lvalue if T is an lvalue referencetype or an rvalue reference to function type and an xvalue if T is an rvalue reference to object type; otherwisethe result is a prvalue. [ Note: if T is a non-class type that is cv-qualified, the cv-qualifiers are ignored whendetermining the type of the resulting prvalue; see 3.10. — end note ]2An explicit type conversion can be expressed using functional notation (5.2.3), a type conversion operator(dynamic_cast, static_cast, reinterpret_cast, const_cast), or the cast notation.cast-expression:unary-expression( type-id ) cast-expression3Any type conversion not mentioned below and not explicitly defined by the user (12.3) is ill-formed.4The conversions performed by— a const_cast (5.2.11),— a static_cast (5.2.9),— a static_cast followed by a const_cast,— a reinterpret_cast (5.2.10), or— a reinterpret_cast followed by a const_cast,can be performed using the cast notation of explicit type conversion.
The same semantic restrictions and behaviors apply, with the exception that in performing a static_cast in the following situations the conversionis valid even if the base class is inaccessible:— a pointer to an object of derived class type or an lvalue or rvalue of derived class type may be explicitlyconverted to a pointer or reference to an unambiguous base class type, respectively;— a pointer to member of derived class type may be explicitly converted to a pointer to member of anunambiguous non-virtual base class type;— a pointer to an object of an unambiguous non-virtual base class type, a glvalue of an unambiguousnon-virtual base class type, or a pointer to member of an unambiguous non-virtual base class type80) This includes implicit calls such as the call to an allocation function in a new-expression.§ 5.4© ISO/IEC 2011 – All rights reserved117ISO/IEC 14882:2011(E)may be explicitly converted to a pointer, a reference, or a pointer to member of a derived class type,respectively.If a conversion can be interpreted in more than one of the ways listed above, the interpretation that appearsfirst in the list is used, even if a cast resulting from that interpretation is ill-formed.
If a conversion can beinterpreted in more than one way as a static_cast followed by a const_cast, the conversion is ill-formed.[ Example:struct A { };struct I1 : A { };struct I2 : A { };struct D : I1, I2 { };A *foo( D *p ) {return (A*)( p ); // ill-formed static_cast interpretation}— end example ]5The operand of a cast using the cast notation can be a prvalue of type “pointer to incomplete class type”.The destination type of a cast using the cast notation can be “pointer to incomplete class type”. If both theoperand and destination types are class types and one or both are incomplete, it is unspecified whether thestatic_cast or the reinterpret_cast interpretation is used, even if there is an inheritance relationshipbetween the two classes.
[ Note: For example, if the classes were defined later in the translation unit, amulti-pass compiler would be permitted to interpret a cast between pointers to the classes as if the classtypes were complete at the point of the cast. — end note ]5.51Pointer-to-member operators[expr.mptr.oper]The pointer-to-member operators ->* and .* group left-to-right.pm-expression:cast-expressionpm-expression .* cast-expressionpm-expression ->* cast-expression2The binary operator .* binds its second operand, which shall be of type “pointer to member of T” (whereT is a completely-defined class type) to its first operand, which shall be of class T or of a class of which T isan unambiguous and accessible base class. The result is an object or a function of the type specified by thesecond operand.3The binary operator ->* binds its second operand, which shall be of type “pointer to member of T” (whereT is a completely-defined class type) to its first operand, which shall be of type “pointer to T” or “pointer toa class of which T is an unambiguous and accessible base class.” The expression E1->*E2 is converted intothe equivalent form (*(E1)).*E2.4Abbreviating pm-expression.*cast-expression as E1.*E2, E1 is called the object expression.