Bug 11657 – Pass array literal to typesafe variadic argument on stack

Status
RESOLVED
Resolution
DUPLICATE
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-12-01T10:09:12Z
Last change time
2020-05-10T06:40:59Z
Assigned to
No Owner
Creator
Martin Nowak

Comments

Comment #0 by code — 2013-12-01T10:09:12Z
cat > enh.d << CODE void foo(int[] ary...) { } void bar() { foo([1, 2, 3, 4]); } CODE Currently this allocates a temporary array on the heap. But because it's not allowed to escape variadic arguments, they array can be passed on the stack.
Comment #1 by bearophile_hugs — 2013-12-01T10:33:56Z
(In reply to comment #0) I think this optimization should be implemented only after the "scope" attribute works well enough, see comment 14 in Issue 5212 .
Comment #2 by hsteoh — 2014-05-06T16:51:11Z
Really? variadic arguments are not allowed to escape? Then there is a glaring hole: class C { int[] a; this(int[] data...) { a = data; // compiles } } This case needs to be prohibited, otherwise we end up with bug #5212.
Comment #3 by code — 2014-09-20T19:54:51Z
> Really? variadic arguments are not allowed to escape? Then there is a > glaring hole: Well the hole is called bug 5212 :). Someone should fix it, but the argument is still valid.
Comment #4 by code — 2016-09-24T02:14:59Z
(In reply to Martin Nowak from comment #3) > Well the hole is called bug 5212 :). issue 5212
Comment #5 by pro.mathias.lang — 2020-05-10T06:40:59Z
Marking as duplicate of the (much more recent) issue 20734 which has been fixed. *** This issue has been marked as a duplicate of issue 20734 ***