Bug 24519 – compiler segfault on default argument with slice operator []
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2024-04-23T11:16:39Z
Last change time
2024-04-26T05:09:07Z
Keywords
pull
Assigned to
No Owner
Creator
lucas
Comments
Comment #0 by lr — 2024-04-23T11:16:39Z
I Found that when i use the buildPath() as the only default argument in a class constructor it causes a segment fault in the compiler.
---
import std.path;
class A {
this(string path = buildPath("a", "b")) {
}
}
void main() {
auto a = new A();
}
---
$ dmd --version
> DMD64 D Compiler v2.108.0
$ dmd comp_seq.d
> fish: Job 1, 'dmd comp_seg.d' terminated by signal SIGSEGV (Address boundary error)
$ dmd --version
> DMD64 D Compiler v2.105.2
$ dmd comp_seq.d
> # ok
Comment #1 by dkorpel — 2024-04-24T11:40:42Z
The new code to resolve __FILE__ and __LINE__ in default arguments crashes when walking over a slice generated from a typesafe variadic function. Reduced example:
```
int buildPath(int[] paths...)
{
return 0;
}
void f(int path = buildPath(1, 2))
{
}
void g()
{
f();
}
```
Comment #2 by dkorpel — 2024-04-24T12:13:43Z
It doesn't even require variadic arguments, it's just about the empty slice:
```
void f(string file = ""[])
{
}
void g()
{
f();
}
```
Comment #3 by dlang-bot — 2024-04-24T12:15:18Z
@dkorpel created dlang/dmd pull request #16408 "Fix Bugzilla 24519 - compiler segfault on default argument with slice…" fixing this issue:
- Fix Bugzilla 24519 - compiler segfault on default argument with slice operator []
https://github.com/dlang/dmd/pull/16408
Comment #4 by dlang-bot — 2024-04-24T14:39:01Z
dlang/dmd pull request #16408 "Fix Bugzilla 24519 - compiler segfault on default argument with slice…" was merged into stable:
- a652348f581e84a77e4f895f60ad834f288951b9 by Dennis Korpel:
Fix Bugzilla 24519 - compiler segfault on default argument with slice operator []
https://github.com/dlang/dmd/pull/16408
Comment #5 by dlang-bot — 2024-04-26T05:09:07Z
dlang/dmd pull request #16409 "merge stable" was merged into master:
- 6c501f3e5135602dbf0a8066fa3ff8bc6a4b90f6 by Dennis Korpel:
Fix Bugzilla 24519 - compiler segfault on default argument with slice operator []
https://github.com/dlang/dmd/pull/16409