[Issue 22936] New: Compiler creates char[] pointing to immutable memory
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Mar 25 21:10:03 UTC 2022
https://issues.dlang.org/show_bug.cgi?id=22936
Issue ID: 22936
Summary: Compiler creates char[] pointing to immutable memory
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: jephthah_divots at aleeas.com
---
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]
}
---
--
More information about the Digitalmars-d-bugs
mailing list