January 16, 2023 [Issue 23637] New: [betterC] DMD issues GC usage error during CTFE | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=23637 Issue ID: 23637 Summary: [betterC] DMD issues GC usage error during CTFE Product: D Version: D2 Hardware: All OS: All Status: NEW Severity: normal Priority: P1 Component: dmd Assignee: nobody@puremagic.com Reporter: jack@jackstouffer.com The following code does not compile char[] unsignedToTempString(uint radix = 10)(ulong value, return scope char[] buf) @safe if (radix >= 2 && radix <= 16) { size_t i = buf.length; do { uint x = void; if (value < radix) { x = cast(uint)value; value = 0; } else { x = cast(uint)(value % radix); value /= radix; } buf[--i] = cast(char)((radix <= 10 || x < 10) ? x + '0' : x - 10 + 'a'); } while (value); return buf[i .. $]; } char[] myToString(ulong n) { char[20] buf; auto s = unsignedToTempString(n, buf); return s ~ (n > uint.max ? "UL" : "U"); } enum a = myToString(5); Fails with Error: array concatenation of expression `cast(const(char)[])s ~ (n > 4294967295LU ? "UL" : "U")` requires the GC which is not available with -betterC -- |
Copyright © 1999-2021 by the D Language Foundation