Bug 21984 – duping a recursive ctfe param can crash dmd

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-05-28T18:42:16Z
Last change time
2024-12-13T19:16:42Z
Assigned to
No Owner
Creator
Adam D. Ruppe
Moved to GitHub: dmd#18038 →

Comments

Comment #0 by destructionator — 2021-05-28T18:42:16Z
This is weird and I don't even know how to describe it. Just try compiling this code: --- struct ContainerMeta { string s; ContainerMeta[] children; } template Container(Thing) { class Container : Thing { static ContainerMeta opCall(ContainerMeta[] children...) { return ContainerMeta( "", children.dup, ); } } } //void main() { @Container!Object() struct A { } //} --- I get all this here: /home/me/d/dmd2/linux/bin64/../../src/druntime/import/object.d(3473): Error: cannot append type `const(ContainerMeta)` to type `ContainerMeta[]` /home/me/d/dmd2/linux/bin64/../../src/druntime/import/object.d(3460): Error: template instance `object._dup!(const(ContainerMeta), ContainerMeta)` error instantiating /home/me/d/dmd2/linux/bin64/../../src/druntime/import/object.d(3424): instantiated from here: `_trustedDup!(const(ContainerMeta), ContainerMeta)` bugctfe.d(11): instantiated from here: `dup!(ContainerMeta)` bugctfe.d(18): instantiated from here: `Container!(Object)` bugctfe.d(18): Error: CTFE failed because of previous errors in `opCall` In the code I reduced this out of, dmd also segfaulted, but I couldn't reproduce that in the minimized example. Now, I also left that commented main() thing because if you uncomment that, it all works fine. So apparently nested structs - including static nested structs - are ok, but top-level thing is not. My guess is probably some semantic order problem. The variadic thing btw is secondary, I tried doing it with a plain array and explicitly passing empty too and it failed. Interestingly removing the `string s` also let it work. So very strange.
Comment #1 by robert.schadek — 2024-12-13T19:16:42Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18038 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB