https://issues.dlang.org/show_bug.cgi?id=16030
Issue ID: 16030
Summary: bad error message when trying to use union in CTFE
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Keywords: diagnostic
Severity: minor
Priority: P1
Component: dmd
Assignee: [email protected]
Reporter: [email protected]
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".
--