"Johann MacDonagh" <johann.macdonagh....@spam..gmail.com> wrote in message news:iusp80$vnr$1...@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(); }