C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Relocation in C++

From: Sebastian Wittmeier <wittmeier_at_[hidden]>
Date: Thu, 22 Dec 2022 12:17:40 +0100
If the destructor is called on the reference, the original object would be destroyed.   -----Ursprüngliche Nachricht----- Von:Edward Catmur <ecatmur_at_[hidden]> Gesendet:Do 22.12.2022 12:00 Betreff:Re: [std-proposals] Relocation in C++ An:std-proposals_at_[hidden]; CC:Sebastian Wittmeier <wittmeier_at_[hidden]>; On Thu, 22 Dec 2022 at 11:53, Sebastian Wittmeier via Std-Proposals <std-proposals_at_[hidden] <mailto:std-proposals_at_[hidden]> > wrote: `reloc localvar` or `reloc param` are a solution to 'undefine' variable or parameter names within scope or function boundaries. The same would not be possible for reference names only:   MyType a{}; MyType& b = a; reloc b;   Would destroy and 'undefine' b, accessing a afterwards would be UB. Right?  No, that will end the lifetime of the reference. `a` will be unaffected.  There would be no simple/analog way to only undefine b, but keep a intact. That is just how references are working. OTOH, `reloc a` gives a way to undefine a variable and it would be nice to do the same for a reference.

Received on 2022-12-22 11:17:42