Bug 22936 – Compiler creates char[] pointing to immutable memory

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2022-03-25T21:10:03Z
Last change time
2024-12-13T19:21:42Z
Assigned to
No Owner
Creator
Andrei Horodniceanu
Moved to GitHub: dmd#18093 →

Comments

Comment #0 by a.horodniceanu — 2022-03-25T21:10:03Z
--- char[] s = "hello".dup; void main () { s[0] = 'X'; // segfault } --- --- char[] h () { return ['h']; } char[] s = h() ~ "i"; void main () { s[0] = 'X'; // segfault } --- These bugs seem to be caused due to CTFE evaluating expresions to a diferent type than what would be produced at runtime: --- char[] h () { return ['h']; } void main () { // Literals seem to be evaluated similarly to runtime pragma(msg, (['h'] ~ "i").ptr); // &['h', 'i'][0] pragma(msg, (h() ~ "i").ptr); // &"hi"[0] } ---
Comment #1 by robert.schadek — 2024-12-13T19:21:42Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18093 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB