Steven Schveighoffer <> changed:

           What    |Removed                     |Added
             Status|RESOLVED                    |REOPENED
                 CC|                            |
         Resolution|DUPLICATE                   |---
            Summary|postblit behaves            |postblit should allow
                   |inconsistently with         |writing const/immutable
                   |constants                   |members just like
                   |                            |constructors

--- Comment #2 from Steven Schveighoffer <> ---
I think the OP has a point here.

A more direct example:

struct S
   const char[] t;
      t = t.dup;     // this should be allowed
      // t[0] = 'w'; // this should not

S s;

// Should be OK, calls postblit, s2 is new data.
auto s2 = s;

// error cannot overwrite const (does not call postblit). This happens already
s = s2;

essentially, when READING `this`, all normal rules apply. When WRITING members
of `this`, everything should be considered tail-X, where X is const, immutable,
etc. If we have any immutable or const data as members, the compiler should
have already forbade it if you couldn't overwrite it before the postblit.

It's the same as constructors, but for constructors, `this` didn't exist yet.
If we get to a postblit on a type that has const or immutable data, we have the
same guarantee.

This does not address postblits being called on const data types (with `this`
being mutable during the postblit). That is a different bug.


Reply via email to