Bug 20770 – error: cannot pass types that need destruction as variadic arguments

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-04-26T14:26:20Z
Last change time
2024-12-13T19:08:18Z
Assigned to
No Owner
Creator
Iain Buclaw
Moved to GitHub: dmd#19696 →

Comments

Comment #0 by ibuclaw — 2020-04-26T14:26:20Z
Sample program: ``` import core.stdc.stdarg; import core.stdc.stdio; struct Foo { int fld; //this(this) { } ~this() { } // Make it non-POD. } void variableFoo(int num, ...) { va_list va; va_start(va, num); foreach (i; 0 .. num) { auto arg = va_arg!Foo(va); printf("fld = %d\n", arg.fld); } } void main() { auto f1 = Foo(1); auto f2 = Foo(2); auto f3 = Foo(3); variableFoo(3, f1, f2, f3); } ``` There is no reason why internally these can't be passed by invisible reference. va_arg!() will need to be fixed in order to support this.
Comment #1 by kinke — 2020-04-26T18:02:56Z
(In reply to Iain Buclaw from comment #0) > There is no reason why internally these can't be passed by invisible > reference. Not so sure about that; normally, the compiler creates a temporary in the caller, passes it by hidden ref, and lets the callEE destruct the temporary. In the vararg case, there's no formal parameter, and the callee doesn't destruct.
Comment #2 by ibuclaw — 2020-04-27T15:02:45Z
structs with postblits and copy-ctors need to have the same applied as well.
Comment #3 by robert.schadek — 2024-12-13T19:08:18Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19696 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB