swap doesn't work in CTFE?
Daniel Murphy
yebblies at nospamgmail.com
Mon Jul 4 10:34:28 PDT 2011
"Johann MacDonagh" <johann.macdonagh..no at spam..gmail.com> wrote in message
news:iusp80$vnr$1 at digitalmars.com...
> Although CTFE supports ref parameters, swap doesn't appear to work. This
> casues dmd to segfault in 2.053 and the current dmd master.
>
> import std.algorithm;
> import std.stdio;
>
> string ctfeRef(ref string a, ref string b)
> {
> return a;
> }
>
> string ctfeSort()
> {
> auto x = [ "a", "c", "b" ];
> swap(x[1], x[0]); // This is the problem here
> return ctfeRef(x[1], x[0]);
> }
>
> void main()
> {
> enum xx = ctfeSort();
> writeln(xx);
> }
>
> This means things like sort won't work in CTFE. Does anyone know if this
> is a known bug? My searching didn't bring anything up.
Same thing happens with pointers. Reduced:
void swap(int[]* lhs, int[]* rhs)
{
*lhs = *rhs;
*rhs = *lhs;
}
int ctfeSort()
{
int[][2] x;
swap(&x[0], &x[1]);
return 0;
}
void main()
{
enum x = ctfeSort();
}
More information about the Digitalmars-d-learn
mailing list