What    |Removed                     |Added
             Status|NEW                         |RESOLVED
                 CC|                            |
         Resolution|---                         |DUPLICATE

--- Comment #1 from ---
(In reply to Ajieskola from comment #0)
> Postblits behave inconsistently with constants. As shown in the second
> example, it cannot modify members which are declared as const. But if that
> is wrong, the first one should compile neither, as all the members should be
> treated as const when the whole variable is const.

The first example shouldn't compile.

`title = title.dup;` doesn't do any actual harm, because you're not altering
the original. But consider `title[0] = 'W';`. Now you're changing the original
`title` to "Wondon bridge", and you're doing it through a `const` reference.
That should not be possible. Even worse, the original title could be

import std.stdio;
struct placeAtWorldMap
{   char[] title;

    {   title[0] = 'W'; /* ! */
void main()
{   immutable char[] title = "London bridge".dup;
    const place = const placeAtWorldMap(title);
    const samePlace = place;
    title.writeln; // Wondon bridge

Issue 18357 already covers that problem. Closing as DUPLICATE. Feel free to
revert if you think it's not an exact duplicate.

*** This issue has been marked as a duplicate of issue 18357 ***


Reply via email to