Bug 22617 – CTFE rejects modification of copied static array

Status
NEW
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-12-21T13:18:14Z
Last change time
2024-12-13T19:20:00Z
Keywords
rejects-valid
Assigned to
No Owner
Creator
moonlightsentinel
See also
https://issues.dlang.org/show_bug.cgi?id=24354
Moved to GitHub: dmd#18073 →

Comments

Comment #0 by moonlightsentinel — 2021-12-21T13:18:14Z
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.
Comment #1 by razvan.nitu1305 — 2022-01-27T15:28:35Z
Comment #2 by robert.schadek — 2024-12-13T19:20:00Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18073 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB