On Thu, 22 Dec 2022 at 12:17, Sebastian Wittmeier <wittmeier@projectalpha.org> wrote:

If the destructor is called on the reference, the original object would be destroyed.

 Then it's just as well that that isn't what happens. Instead, the lifetime of the variable is ended in the same manner as when an automatic variable reaches end of scope:

std::string s;
    auto& r = s;
}  // #1
auto& q = s;
reloc q;  // #2

The effect of #2 (as a discarded-value relocation expression) is precisely the same as that of #1.

-----Ursprüngliche Nachricht-----
Von: Edward Catmur <ecatmur@googlemail.com>
Gesendet: Do 22.12.2022 12:00
Betreff: Re: [std-proposals] Relocation in C++
An: std-proposals@lists.isocpp.org;
CC: Sebastian Wittmeier <wittmeier@projectalpha.org>;
On Thu, 22 Dec 2022 at 11:53, Sebastian Wittmeier via Std-Proposals <std-proposals@lists.isocpp.org> 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.