Bug 21482 – dynamic indexing into enum dynamic array at ctfe generates TypeInfo in betterC

Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-12-15T01:15:23Z
Last change time
2023-04-10T10:04:09Z
Keywords
betterC
Assigned to
No Owner
Creator
dave287091
See also
https://issues.dlang.org/show_bug.cgi?id=21492

Comments

Comment #0 by dave287091 — 2020-12-15T01:15:23Z
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.
Comment #1 by dave287091 — 2020-12-15T01:30:29Z
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; }
Comment #2 by bugzilla — 2023-01-15T07:36:28Z
The current error message is: Error: expression `[1, 2, 3]` uses the GC and cannot be used with switch `-betterC`
Comment #3 by razvan.nitu1305 — 2023-04-10T10:04:09Z
This seems to have been fixed. this compiles successfully with the latest compiler.