www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22617] New: CTFE rejects modification of copied static array


          Issue ID: 22617
           Summary: CTFE rejects modification of copied static array
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: regression
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: moonlightsentinel disroot.org

CTFE rejects the assignment to `copy[0]` if `arr` is const/immutable even
though the static array was copied!

int countWins(const uint[2] arr)
        uint[2] copy = arr;
        copy[0] = 0;
        return 0;

enum force = countWins([4, 8]);

ctfe_copy.d(4): Error: cannot modify read-only constant `[4u, 8u]`
ctfe_copy.d(8):        called from here: `countWins([4u, 8u])`


Introduced by https://github.com/dlang/dmd/pull/4503.

Dec 21 2021