Rebooting the __metada/__mutable discussion

Paul Backus snarwin at gmail.com
Mon Apr 11 17:17:46 UTC 2022


On Monday, 11 April 2022 at 16:40:42 UTC, Alexandru Ermicioi 
wrote:
> On Monday, 11 April 2022 at 14:44:18 UTC, Paul Backus wrote:
>> There's no issue here. You just write the copy constructor of 
>> RC!T to require a mutable source and destination object, and 
>> the compiler will refuse to copy a const(RC!T). (You can still 
>> pass by `const ref`, of course.)
>
> Obviously there are:
>
> [...]

I don't see what the problem here is. Two instances of 
`Counted!int` are created, and both are destroyed. No references 
are leaked or left dangling. If you try to copy-construct an 
additional instance, like

     auto r5 = r4;

...then the compiler correctly rejects the code.

Granted, it only works because the compiler-inserted destructor 
call ignores `const`, which is a little questionable, but I think 
in this case it's basically harmless.


More information about the Digitalmars-d mailing list