Bug 16030 – bad error message when trying to use union in CTFE

Status
NEW
Severity
minor
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2016-05-16T11:12:21Z
Last change time
2024-12-13T18:47:46Z
Keywords
diagnostic
Assigned to
No Owner
Creator
ag0aep6g
Moved to GitHub: dmd#19123 →

Comments

Comment #0 by ag0aep6g — 2016-05-16T11:12:21Z
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
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19123 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB