Deprecating this(this)

Nicholas Wilson iamthewilsonator at hotmail.com
Sun Apr 1 14:31:06 UTC 2018


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. To cleanly deal with const, you 
> need something more like a copy constructor where you 
> initialize it with the adjusted values directly rather than 
> mutating the copy.

I've always wondered about that, is the difference between that 
anything more than philosophical? Put another way if a this(this) 
is weakly pure, is there any safety issues with the compiler 
permitting the mutation on a (non-shared? not sure if this would 
be a requirement) const object? I'm not sure what the spec says, 
but if you take the view that the const object is no fully 
initialised until the postblit is done, then I don't see the 
problem.


More information about the Digitalmars-d mailing list