import std.algorithm;
import std.typecons;
auto foo() {
enum n = 1000;
auto x = new Tuple!int[n];
x.sort;
return x;
}
enum a = foo;
void main() {
}
/dlang/dmd/linux/bin64/../../src/phobos/std/algorithm/mutation.d(2825): Error: reinterpreting cast from Tuple!int* to ubyte* is not supported in CTFE
Compiles for n == 100.
Comment #1 by bugzilla — 2021-05-03T14:03:20Z
Meanwhile n == 100 produces:
/home/D/Repo/dmd/generated/linux/release/64/../../../../../druntime/import/core/lifetime.d(2105): Error: `memcpy` cannot be interpreted at compile time, because it has no available source code
(using DMD64 D Compiler v2.096.1-242-g9fd50d0be)
It still works for n <= 5.
Comment #2 by tim.dlang — 2021-11-04T18:23:06Z
It also fails for small arrays, but only if some elements have to be swapped:
enum x = (){
import std.algorithm, std.typecons;
auto x = [tuple!int(2), tuple!int(1)];
x.sort;
return x;
}();
The problem can also be reproduced by calling swap directly:
enum x = (){
import std.algorithm, std.typecons;
Tuple!int a, b;
swap(a, b);
return 0;
}();
Comment #3 by nick — 2023-12-18T12:24:33Z
I've split out the swap error to issue #24285.
With the swap fix, the comment #1 error still happens.
Comment #4 by robert.schadek — 2024-12-01T16:38:04Z