std.format and uninitialized elements in CTFE

berni44 dlang at d-ecke.de
Thu Dec 5 18:37:03 UTC 2019


std.format contains code, that accesses the members of a struct 
via tupleof (which gives access to private members, that might be 
intentionally not yet initialized), to print them. If members are 
not initialized it produces a "used before initialized" error or 
something similar. (See issue 19769 [1]).

What to do about this? Should std.format check if the members of 
a struct are not initialized and do what in that case? And how to 
check them?

Here an example:

```
import std.format;

struct Foo
{
     int a = void;
}

static x = format("%s", Foo());
```

Replace int by int[3] for a more complex version.

[1] https://issues.dlang.org/show_bug.cgi?id=19769


More information about the Digitalmars-d mailing list