C++ Logo

std-discussion

Advanced search

[basic.life]#8 contradictions

From: Mykola Garkusha <garkusha.mykola_at_[hidden]>
Date: Mon, 2 Oct 2023 11:50:56 +0100
Trying to make sense of the [basic.lifetime] section of the standard, but
it appears to be contradictive in a few places.

While I'm generally I'm aware that there is work still going on to further
improve the standard, there is one particular contradiction that I haven't
seen covered. http://eel.is/c++draft/basic#life-8 places restrictions in
case the object lifetime ended but **before** the storage has been *
*released** or **re-used**. While mentioning **released** makes sense, *
*re-used**, in my opinion, brings contradiction since most often the new
object would be created using placement new, and now the latest
standard does clearly mention that storage is first released in placement
new, and then the new object is created [
http://eel.is/c++draft/basic#life-1.5]

Wouldn't the drop of **re-used** from http://eel.is/c++draft/basic#life-8
make it non-contradictive? My reasoning is that as **re-used** is defined
at least for placement new (maybe *memcpy *as well?) the following code
from the example in [basic.life]#8

this->~C(); // lifetime of *this ends
new (this) C(other); // new object of type C created. But why storage is
not considered *re-used* given new rules in [basic.life]#1 around placement
new

would imply the following sequence of ordered events
(1) *end of a lifetime for the object which this used to point to -> *
*(2)* *storage which this used to to point is *re-used* [basic.life]#1* ->
*(3) new object C is created at the storage which is used to point to*

Then if the above is correct, the condition is in [basic.life]#8 cannot
apply to the corresponding example as *(1) *happens before *(2)* and *(2)*
happens before *(3)*. Now if *(2)* would have been dropped as the required
condition then it would all make sense. However looks like from the
comment in the example above, that the standard omits **re-use** in "new (
this) C(other"

Any thoughts on this? Or I've missed some important piece in my reasoning?

Kind Regards,
  Mykola

Received on 2023-10-02 10:51:08