C++ Logo


Advanced search

Re: std::atomic_ref lifetime

From: Edward Catmur <ecatmur_at_[hidden]>
Date: Thu, 28 Jul 2022 20:45:58 +0100
On Thu, 28 Jul 2022 at 20:34, Артём Колпаков via Std-Discussion <
std-discussion_at_[hidden]> wrote:

> To the topic. In the following sentence of the standard: "The lifetime
> ([basic.life]) of an object referenced by *ptr shall exceed the lifetime of
> all atomic_­refs that reference the object.
> <http://eel.is/c++draft/atomics.ref.generic.general#3.sentence-1>", I
> can't understand why, instead of lifetime restrictions, do not prohibit the
> use of std::atomic_ref after the lifetime of the referenced object ends
> (like dangling references). This is inconvenient, because before deleting
> an object, you have to delete atomic_ref. Even more, the restriction from
> the standard does not allow, as it seems to me, to use valid programs.

This restriction is termed "pointer lifetime-end zap". See
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p1726r5.pdf for
historical background;
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2414r1.pdf and
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p2188r1.html for
some proposed approaches to a solution.

Received on 2022-07-28 19:46:11