A trick that Andrei and I came up with not long ago, to use alloca as part of a default argument does not work any more. I developed this with someone on #D one night and use it everywhere I need to pass a D string to a C API.
Use cases:
http://forum.dlang.org/thread/[email protected]#post-i1gql2:241k6o:241:40digitalmars.comhttps://github.com/mleise/fast/blob/master/source/fast/cstring.d#L92
---------------8<----------------
import core.stdc.stdlib;
enum allocaLimit = 1024;
auto wcharPtr(alias str)(void* buffer = 2*(str.length+1) <= allocaLimit ? alloca(2*(str.length+1)) : null)
{
// ...
}
void main()
{
wcharPtr!"abc"w;
}
------------->8----------------
Comment #1 by dlang-bugzilla — 2014-09-07T13:00:03Z
(In reply to Vladimir Panteleev from comment #1)
> Introduced in https://github.com/D-Programming-Language/dmd/pull/3811 ,
> which fixed issue 12820. Looks like it may have been intentional.
In terms of what that pull fixed, namely bug https://issues.dlang.org/show_bug.cgi?id=12820 , it is a false positive. The alloca() call in this regression is not inside the function, but on the caller side where the default arguments are filled in. So it is (or at least I understand it like that) semantically equivalent to:
wcharPtr!"abc"w(alloca(123));