-
-
Notifications
You must be signed in to change notification settings - Fork 614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Array literal shouldn't cause GC allocation for void
element types
#20668
Comments
Why does a |
It does make sense. The size is known, the length is in bytes of the original slice. See https://dlang.org/spec/arrays.html#void_arrays
The main difference from |
I think void main()
{
ubyte[] b = [0x00]; // [cast(ubyte) 0]
writeln(b.length); // 1
void[] v = [0x00]; // cast(void[]) [0]
writeln(v.length); // 4
void[1] bar = [0x00]; // Range violation (4 bytes assigned to 1 byte)
// void[4] bar = [0x00]; // Error: Mismatched array lengths, 4 and 1
} We need to decide whether integers in array literals converted to void[] represent 4 bytes or 1. |
Luckily, that's |
Btw, there is no problem regarding GC with D optimisations in LDC, as we benefit from the lowering from GC to stack transformation passes, see https://godbolt.org/z/1c77P8xY6 . |
This compiles:
Although, this doesn't, but should:
The text was updated successfully, but these errors were encountered: