945 – template forward reference with named nested struct only

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 945 - template forward reference with named nested struct only
Summary: template forward reference with named nested struct only
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: patch, rejects-valid
Depends on: 810
Blocks: 340
Show dependency tree / graph
Reported: 2007年02月10日 10:10 UTC by Manuel König
Modified: 2014年02月16日 15:23 UTC (History)
4 users (show)

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description Manuel König 2007年02月10日 10:10:57 UTC
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 Stewart Gordon 2007年02月10日 10:30:18 UTC
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 Manuel König 2007年02月10日 11:25:19 UTC
d-bugmail@puremagic.com schrieb:
> http://d.puremagic.com/issues/show_bug.cgi?id=945
> 
> 
> smjg@iname.com changed:
> 
> What |Removed |Added
> ----------------------------------------------------------------------------
> CC| |smjg@iname.com
> Keywords| |rejects-valid
> 
> 
> 
> 
> ------- Comment #1 from smjg@iname.com 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 Manuel König 2007年02月10日 11:50:13 UTC
d-bugmail@puremagic.com schrieb:
> http://d.puremagic.com/issues/show_bug.cgi?id=945
> 
> 
> smjg@iname.com changed:
> 
> What |Removed |Added
> ----------------------------------------------------------------------------
> CC| |smjg@iname.com
> Keywords| |rejects-valid
> 
> 
> 
> 
> ------- Comment #1 from smjg@iname.com 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 Stewart Gordon 2007年02月10日 12:09:51 UTC
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 Nicolay Korslund 2007年08月20日 07:56:46 UTC
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 Rainer Schuetze 2010年03月27日 06:22:43 UTC
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 Walter Bright 2010年05月10日 11:45:01 UTC
changeset 478
Comment 8 Don 2010年05月18日 12:15:17 UTC
Fixed DMD1.061 and DMD2.046.


AltStyle によって変換されたページ (->オリジナル) /