__rvalue and Move Semantics first draft - aliasing problem/danger

Timon Gehr timon.gehr at gmx.ch
Sun Nov 10 17:36:25 UTC 2024


On 11/9/24 23:44, Walter Bright wrote:
> I'm not sure it's a problem or a danger.
> 
> Timon mentioned the related problem with:
> 
> ```
> callee(__rvalue s, __rvalue s);
> ```
> 
> where s would be destroyed twice. This isn't always detectable:
> ```
> S* ps = ...;
> callee(__rvalue *s, __rvalue(*s));
> ```
> But can be rendered benign with the blit of S.init after the destructor 
> call.

I think the main potential trouble is that there is usually an 
assumption that there is no aliasing between rvalue arguments.

For example, if a compiler backend assumes no aliasing, undefined 
behavior might be introduced if one of the arguments is modified and 
then the other is read.

Of course, we can instead specify that the aliasing is legal (but it may 
still be surprising).


More information about the dip.development mailing list