Compiling with DMD, with -betterC DMD64 D Compiler v2.094.2-336-g97aa2ae5e // works int f_1(int a){ enum int[]foo = [1,2,3]; if(__ctfe) return foo[1]; return 1; } // works int f_2(int a){ static immutable int[] foo = [1,2,3]; if(__ctfe) return foo[a]; return 2; } // fails with TypeInfo cannot be used with -betterC int f_3(int a){ enum int[]foo = [1,2,3]; if(__ctfe) return foo[a]; // Error is reported at this line. return 3; } All three work with ldc.
I have discovered that a workaround is as follows: int f_4(int a){ enum int[]foo_ = [1,2,3]; enum int[foo_.length]foo = foo_; if(__ctfe) return foo[a]; return 4; }
The current error message is: Error: expression `[1, 2, 3]` uses the GC and cannot be used with switch `-betterC`
This seems to have been fixed. this compiles successfully with the latest compiler.