This analysis is based on n4567 and uses the partition numbers from it.
§5.2.10 / 7: When a prvalue v type of an object pointer is converted to an object pointer type of "pointer to cv T", the result is static_cast<cv T*>(static_cast<cv void*>(v)) .
So, in this case, reinterpret_cast<X*>(buffer) same as static_cast<X *>(static_cast<void *>(buffer)) . This leads us to consider the relevant parts about static_cast :
§5.2.9 / 13: prvalue of type "pointer to cv1 void" can be converted to prvalue of type "pointer to cv2 T", where T is the type of object and cv2 is the same cv qualification as or more cv qualifications than cv1. The null pointer value is converted to the null pointer value for the destination type. If the initial value of the pointer represents the address A byte in memory, and A satisfies the alignment requirement T , then the obtained value of the pointer represents the same address as the original value of the pointer, that is, A
I believe that it is enough to say that the original quote is correct - this conversion gives certain results.
As for the lifetime, it depends on what kind of life you are talking about. The cast creates a new object of the type of the pointer - temporary, which has a lifespan starting from the line in which the throw is located and ends when it goes beyond the bounds. If you have two different transformations that occur conditionally, each pointer has a lifespan that begins with the location of the throw it created.
None of them affects the lifetime of the object that provides the underlying storage, which is still buffer , and has exactly the same lifetime, regardless of whether you create a pointer (of the same or converted type) for this storage or not.
Jerry Coffin Nov 29 '16 at 19:15 2016-11-29 19:15
source share