Deprecating this(this)

Nicholas Wilson iamthewilsonator at hotmail.com
Mon Apr 2 14:24:20 UTC 2018


On Monday, 2 April 2018 at 14:07:21 UTC, Steven Schveighoffer 
wrote:
> On 4/1/18 10:34 AM, ag0aep6g wrote:
>> On Sunday, 1 April 2018 at 13:37:43 UTC, Jonathan M Davis 
>> wrote:
>>> One issue is that postblit constructors fundamentally don't 
>>> work with const. The problem is that a postblit constructor 
>>> works by copying the object and _then_ mutating it, and you 
>>> can't mutate a const object.
>> 
>> I'm not so sure if that's fundamental. Can't we just say that 
>> the copy is head-mutable at the time when the postblit 
>> function is called, and it only becomes fully const after that?
>> 
>> The destination can't be const/immutable already, or you 
>> wouldn't be able to write there anyway.
>
> Yes, precisely what I had been arguing here: 
> https://issues.dlang.org/show_bug.cgi?id=18417#c5, however 
> const/immutable postblit was recently deprecated by: 
> https://github.com/dlang/dmd/pull/8032
>
> So I don't think D is going to allow const postblit any more. 
> Maybe not even postblit any more.
>
> -Steve

Andrei did post an example where treating the designation as 
mutable, stuffing references to mutable data into is and then 
treating it as immutable leaves you with an immutable reference 
to immutable data.

However i think that loophole is fixed if you only allow 
assignment to const/immutable from a pure postblit.



More information about the Digitalmars-d mailing list