Bug 24456 – CTFE implicit conversion to void[] produces wrong length

Status
NEW
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2024-03-27T13:04:24Z
Last change time
2024-12-13T19:34:07Z
Keywords
CTFE
Assigned to
No Owner
Creator
Bastiaan Veelo
Moved to GitHub: dmd#20424 →

Comments

Comment #0 by Bastiaan — 2024-03-27T13:04:24Z
``` void check(void[] v, size_t len) { import std.conv; assert(v.length == len, "v.length is " ~ v.length.to!string ~ ", expected " ~ len.to!string); } int implicitConversion() { int[2] arr; check(arr, 8); return 42; } int noConversion() { ubyte[8] arr; check(arr, 8); return 42; } struct S { int i = implicitConversion; // Error: "v.length is 2, expected 8" int j = noConversion; // Fine } void main() { int i = implicitConversion; // Fine int j = noConversion; // Fine } ``` This problem surfaced while trying do statically initialize an instance of std.bitmanip.BitArray.
Comment #1 by b2.temp — 2024-03-27T13:37:09Z
compile-time evaluation bug. minimized to ```d enum int[2] a = [0,1]; static assert((cast(void[])a).length == 8); ```
Comment #2 by robert.schadek — 2024-12-13T19:34:07Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20424 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB