[Issue 24351] New: Cannot format `void[]` at compile time

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Jan 22 08:04:54 UTC 2024


https://issues.dlang.org/show_bug.cgi?id=24351

          Issue ID: 24351
           Summary: Cannot format `void[]` at compile time
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody at puremagic.com
          Reporter: ogion.art at gmail.com

This affects all functions that use `formattedWrite`: `format`, `sformat`,
`writef`, `writefln` etc.

```
import std.format : format;
int[] arr = [1, 2, 3, 4];
auto s1 = format("%s", cast(void[])arr); // Works
auto s2 = format!"%s"(cast(void[])arr); /* Error: array cast from `void[]` to
`const(ubyte[])` is not supported at compile time */
```

Compile time `formattedWrite` validates the format string by trying to call a
regular `formattedWrite` with dummy arguments at compile time. This fails
because `void[]` is formatted by casting it to `const(ubyte[]), and casts are
not allowed at compile time.

--


More information about the Digitalmars-d-bugs mailing list