Bug 4516 – Regression(2.040): forward declaration of enum not supported

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
All
Creation time
2010-07-27T00:21:00Z
Last change time
2010-08-30T04:44:46Z
Keywords
patch, rejects-valid
Assigned to
nobody
Creator
braddr
Blocks
340

Comments

Comment #0 by braddr — 2010-07-27T00:21:19Z
module foo; struct A { B b; } enum B { Z } $ dmd -c foo.d foo.d(3): Error: enum B is forward referenced (flagging as D2 only since I haven't tested with D1 -- quite possibly broken with both)
Comment #1 by leandro.lucarella — 2010-07-27T06:42:08Z
(In reply to comment #0) > (flagging as D2 only since I haven't tested with D1 -- quite possibly broken > with both) Nope, D2-only (at least svn r584 works).
Comment #2 by clugdbug — 2010-07-27T07:31:12Z
(In reply to comment #1) > (In reply to comment #0) > > (flagging as D2 only since I haven't tested with D1 -- quite possibly broken > > with both) > > Nope, D2-only (at least svn r584 works). It failed up to D1.053. It works in D1.054 and later. Interestingly it also worked in D2.038 and 2.039 ONLY (released with 1.054), it had failed in 2.037 and earlier, but failed again starting with 2.040.
Comment #3 by dfj1esp02 — 2010-07-28T11:41:50Z
See bug 1160
Comment #4 by clugdbug — 2010-08-06T02:23:31Z
The fix to bug 1160 was what originally fixed it (in toBasetype(), do full semantic on the enum type when forward referenced); the fix to bug 3723 broke it again (in toBasetype(), only do semantic on the type, not on the full enum). In this situation, it does actually does the need the full semantic to be run. Although this test case passes in D1, I'm not convinced that D1 is correct (it doesn't check for forward references at all). ---- PATCH: mtype.c, line 6340. int TypeEnum::isZeroInit(Loc loc) { + if (!sym->defaultval && sym->scope) + { // Enum is forward referenced. We need to resolve the whole thing. + sym->semantic(NULL); + } if (!sym->defaultval) { #ifdef DEBUG printf("3: "); #endif error(loc, "enum %s is forward referenced", sym->toChars()); return 0; } return sym->defaultval->isBool(FALSE); }
Comment #5 by bugzilla — 2010-08-08T20:51:50Z
You're right that D1 doesn't check for it, as defaultVal is just an integer. I'll apply your fix for D2, but leave the bug open for D1. http://www.dsource.org/projects/dmd/changeset/605
Comment #6 by clugdbug — 2010-08-29T23:59:47Z
I have moved the D1 version of this bug into the newly created bug 4768. Both symptoms and solution are different for D1.
Comment #7 by smjg — 2010-08-30T04:44:46Z
But you left this one filed as a D1 bug.