Bug 21034 – concatenation with a string literal could also append the trailing null

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-07-11T01:23:05Z
Last change time
2024-12-13T19:10:02Z
Assigned to
No Owner
Creator
basile-z
Moved to GitHub: dmd#19743 →

Comments

Comment #0 by b2.temp — 2020-07-11T01:23:05Z
This currently fails: --- void main() { string s = "0123"; auto c = &s[2]; s = "0"; s = s ~ "1"; assert(*c == '\0'); } --- this would be a enhacement to support this. Example: add an extension and pass the .ptr property directly to a C style API, without having to call toUTFz / toStringz
Comment #1 by nick — 2023-07-14T13:22:46Z
The assert would fail anyway, because "0123" is immutable data. When you assign "0" to s, that is different memory and cannot affect c. Presumably this request is for: s = "0"; s = s ~ "1"; assert(s.ptr[2] == '\0'); That would cause unnecessary writes when appending a (short) string in a loop and each null byte is not read.
Comment #2 by b2.temp — 2023-07-14T15:16:52Z
More simply: the result of `LHS ~ RHS` should be guaranteed to be zero terminated when RHS is a StringExp.
Comment #3 by robert.schadek — 2024-12-13T19:10:02Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19743 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB