The following code
```
void main()
{
import std.stdio;
auto a = ["c"];
writeln( a ~ "a"); // OK
writeln( a ~ "a" ~ "b"); // CRASH
}
```
used to work and output the right result but it crashes at runtime since recently.
Same problem verified with latest LDC (DMD 2.104.+), showing that the problem might be a caused by a buggy lowering.
reduced w/o phobos
```
extern(C) int puts(const char*);
void main()
{
auto a = ["c\0"];
foreach (v; a ~ "a\0" ~ "b\0")
puts(v.ptr);
}
```
Comment #3 by dlang-bot — 2023-08-19T01:16:58Z
@teodutu created dlang/dmd pull request #15543 "Fix Issue 24078 - Fold constants on array concatenation only for strings" fixing this issue:
- Fix Issue 24078 - Fold constants on array concatenation only for strings
Without this limitation, the code could incorrectly concatenate
`["c"] ~ "a" ~ "b"` as `["c"] ~ "ab"`, which was incorrect.
Signed-off-by: Teodor Dutu <[email protected]>
https://github.com/dlang/dmd/pull/15543
Comment #4 by dlang-bot — 2023-08-19T08:22:03Z
dlang/dmd pull request #15543 "Fix Issue 24078 - Fold constants on array concatenation only for strings" was merged into stable:
- c0de9a32d21bd15ca3ca4c0baaea3a6844122e2d by Teodor Dutu:
Fix Issue 24078 - Fold constants on array concatenation only for strings
Without this limitation, the code could incorrectly concatenate
`["c"] ~ "a" ~ "b"` as `["c"] ~ "ab"`, which was incorrect.
Signed-off-by: Teodor Dutu <[email protected]>
https://github.com/dlang/dmd/pull/15543
Comment #5 by dlang-bot — 2023-09-16T07:31:12Z
dlang/dmd pull request #15609 "merge stable" was merged into master:
- b349b6d0de9d375bda2db418fb16fabe7fc2f031 by Teodor Dutu:
Fix Issue 24078 - Fold constants on array concatenation only for strings
Without this limitation, the code could incorrectly concatenate
`["c"] ~ "a" ~ "b"` as `["c"] ~ "ab"`, which was incorrect.
Signed-off-by: Teodor Dutu <[email protected]>
https://github.com/dlang/dmd/pull/15609