Encountered by Stefan who posted to D.learn:
http://forum.dlang.org/post/[email protected]
Reduced code:
----
union U
{
int i;
byte[4] b;
}
byte[4] f(int val)
{
U u;
u.i = val;
return u.b;
}
static byte[4] forceCtfe = f(1); /* line 14 */
----
Fails compilation with:
----
test.d(14): Error: uninitialized variable 'i' cannot be returned from CTFE
----
I guess it's expected that unions don't work in CTFE, but the error message is bad:
* There is no variable `i` on line 14. The function that actually fails CTFE may be hidden anywhere in the call graph of `f`.
* The function tries to return `u.b`, not `u.i`.
* It's not obvious that "uninitialized" means "from a union".
Comment #1 by robert.schadek — 2024-12-13T18:47:46Z