[Issue 23637] New: [betterC] DMD issues GC usage error during CTFE
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Jan 16 21:04:09 UTC 2023
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 at puremagic.com
Reporter: jack at 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
--
More information about the Digitalmars-d-bugs
mailing list