Bug 945 – template forward reference with named nested struct only

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2007-02-10T10:10:00Z
Last change time
2014-02-16T15:23:54Z
Keywords
patch, rejects-valid
Assigned to
nobody
Creator
manuelk89
Depends on
810
Blocks
340

Comments

Comment #0 by manuelk89 — 2007-02-10T10:10:57Z
Given a struct S in A.d and a template T int B.d with a nested struct and S as its member: // file A.d: import B; struct S { } // file B.d: import A; struct T() { struct Nested { S member; } } ========================================= Compiling with dmd 1.005 on winXP: bud A Yields this: B.d(x): struct B.T!().T.Nested has forward references B.d(x): template instance B.T!() error instantiating But it compiles if... - you make 'Nested' an anonymous struct - you declare 'Nested' somewhere outside of 'T', even after the instantiation - you make 'member' a pointer or S a class - you change compile order, ie. 'bud B' - you put the instantiation below the declaration of S in A.d - you use dmd 0.177 (!) It still does not compile if 'Nested' is made a static struct.
Comment #1 by smjg — 2007-02-10T10:30:18Z
Interesting. Neither dmd A.d B.d dmd B.d A.d shows the problem (trying it under Win98SE). But what puzzles me most is that in your attempt, the compiler prints "x" instead of a line number.
Comment #2 by manuelk89 — 2007-02-10T11:25:19Z
[email protected] schrieb: > http://d.puremagic.com/issues/show_bug.cgi?id=945 > > > [email protected] changed: > > What |Removed |Added > ---------------------------------------------------------------------------- > CC| |[email protected] > Keywords| |rejects-valid > > > > > ------- Comment #1 from [email protected] 2007-02-10 10:30 ------- > Interesting. Neither > > dmd A.d B.d > dmd B.d A.d > > shows the problem (trying it under Win98SE). But what puzzles me most is that > in your attempt, the compiler prints "x" instead of a line number. > > I just used "x" because I didn´t want to count the line numbers and the lines are shifted in my bug report. But the behaviour of "dmd A.d B.d" and vice versa is very interesting, cause manually invoking the compiler with theses lines runs for me too (thanks for the hint!). But both Code::Blocks and 'bud' failed. Under Code::Blocks with full command line logging enabled it says: dmd.exe -I\include -IC:\dmd\src\phobos -c D:\Dev\Projects\DError\B.d -ofobj\Release\B.obj dmd.exe -I\include -IC:\dmd\src\phobos -c D:\Dev\Projects\DError\A.d -ofobj\Release\A.obj dmd.exe bin\Release\DError.exe obj\Release\B.obj obj\Release\A.obj phobos.lib B.d(6): struct B.T!().T.Nested has forward references B.d(11): template instance B.T!() error instantiating Process terminated with status 1 (0 minutes, 0 seconds) 2 errors, 0 warnings I tried to reproduce the error Code::Blocks ran into, but running the same lines from a batch file works! The same error appears by doing 'bud A' (but not 'bud B'!). Can anybody explain this strange behaviour?
Comment #3 by manuelk89 — 2007-02-10T11:50:13Z
[email protected] schrieb: > http://d.puremagic.com/issues/show_bug.cgi?id=945 > > > [email protected] changed: > > What |Removed |Added > ---------------------------------------------------------------------------- > CC| |[email protected] > Keywords| |rejects-valid > > > > > ------- Comment #1 from [email protected] 2007-02-10 10:30 ------- > Interesting. Neither > > dmd A.d B.d > dmd B.d A.d > > shows the problem (trying it under Win98SE). But what puzzles me most is that > in your attempt, the compiler prints "x" instead of a line number. > > This is very embarrissing, but I just forgot the instantiation of the template! It should be: // file A.d: import B; struct S { } // file B.d: import A; struct T() { struct Nested { S member; } } alias T!() instance; // <- add this line!! This should finally reproduce the error!
Comment #4 by smjg — 2007-02-10T12:09:51Z
Please don't blindly quote the entire message when replying. It's bad enough on any old newsgroup, but in this instance it clutters up Bugzilla. (In reply to comment #2) > I just used "x" because I didn´t want to count the line numbers and the > lines are shifted in my bug report. Then leave the compiler output alone. It sometimes helps to add comments to posted code to indicate line numbers.
Comment #5 by korslund — 2007-08-20T07:56:46Z
I have rediscovered this bug while working on a large and very template-heavy project of mine. The project is currently held up by this (and possibly other) template forwarding bugs, and so it would be really appreciated if this bug was fixed in the not too distant future. Thanks ;-)
Comment #6 by r.sagitario — 2010-03-27T06:22:43Z
Here's a patch that invokes the missing semantics. It also fixes issue #1055 Index: struct.c =================================================================== --- struct.c (revision 421) +++ struct.c (working copy) @@ -178,6 +178,8 @@ error("cannot have field %s with same struct type", v->toChars()); } #endif + if (ts->sym->sizeok != 1 && ts->sym->scope) + ts->sym->semantic(NULL); if (ts->sym->sizeok != 1) {
Comment #7 by bugzilla — 2010-05-10T11:45:01Z
changeset 478
Comment #8 by clugdbug — 2010-05-18T12:15:17Z
Fixed DMD1.061 and DMD2.046.