[Issue 18417] Make const and immutable postblit constructors illegal

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Feb 15 16:59:25 UTC 2018


https://issues.dlang.org/show_bug.cgi?id=18417

Steven Schveighoffer <schveiguy at yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |schveiguy at yahoo.com

--- Comment #4 from Steven Schveighoffer <schveiguy at yahoo.com> ---
Posted it on the forums as well, but I'll do so here too:

postblit is what is used to do things like reference counting. You may be
altering data that isn't actually part of the struct, so we still do need a
postblit capability for immutable structs.

Basically the same thing that anonymous4 said, but with a real use case.

(In reply to Jonathan M Davis from comment #3)
> And it's impossible for an immutable or const postblit
> constructor to be called in the first place. If you try and declare a const
> or immutable postblit constructor, you just end up with compilation errors,
> because they don't work - and they can't work, not for what the purpose of a
> postblit constructor is.

The purpose is to run some code after blitting. Which is perfectly reasonable
for immutable and const structs as well.

What we should do is make it possible for immutable/const postblit to work.

i.e.

immutable S s;
immutable y = s; // Error: immutable method S.__postblit is not callable using
a mutable object

Why does it think y is mutable? This should work.

--


More information about the Digitalmars-d-bugs mailing list