Thread overview | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
July 31, 2007 [Issue 1392] New: Templates w/ forwd refs fail when in separate modules. | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=1392 Summary: Templates w/ forwd refs fail when in separate modules. Product: D Version: 1.015 Platform: PC OS/Version: Linux Status: NEW Severity: normal Priority: P2 Component: DMD AssignedTo: bugzilla@digitalmars.com ReportedBy: cdunn2001@gmail.com fooA.d ------ import fooFoo; class A{ static int hi(){ //auto x = new F; //F.there(); return 0; } //Foo!(char) x; }; Foo!(char)* x; --- fooFoo.d -------- import fooA; class Foo(T){ //A* bar(){ // return null; //return A.hi(); //} int i; }; --- I've commented out anything which could confuse the issue. The problem is strictly the circular 'import' of the module which defines the template and the module which specializes it, independent of whether Foo and A actually depend on each other. If these are in the same module, it compiles, even with all the extra stuff, and even with refs instead of pointers. combined.d ---------- alias Foo!(char) F; class A{ static int hi(){ auto x = new F; F.there(); return 0; } F x; }; class Foo(T){ A bar(){ A.hi(); return new A; } int i; }; --- In fact, it works if I compile them at the same time, with: dmd -c fooA.d fooFoo.d Interestingly, this produces two object files, fooA.o and fooFoo.o, which can then be linked into an executable. So the problem comes from compiling just fooFoo.d into fooFoo.o: dmd -c fooFoo.d fooA.d(11): template instance forward reference to template declaration Foo(T) fooA.d(11): Error: Foo!(char) is used as a type In other words, this is not a bug in the language, but rather a bug in compilation. Since I can work around it by just compiling all modules in a package simultaneously, it is not a critical issue, but if it is not fixed, I think people will run into this problem repeatedly. It might make compilation slower too, since in practice, any change will force recompilation of all modules. Please let me know if you need more details. (This is perhaps related to Bug 805 and #877.) -- |
July 31, 2007 [Issue 1392] Templates w/ forwd refs fail when in separate modules. | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=1392 cdunn2001@gmail.com changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |cdunn2001@gmail.com ------- Comment #1 from cdunn2001@gmail.com 2007-07-31 15:27 ------- Oh, I should add that separate module compilation works fine when Foo is not a template. -- |
July 31, 2007 [Issue 1392] Templates w/ forwd refs fail when in separate modules. | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=1392 ------- Comment #2 from cdunn2001@gmail.com 2007-07-31 15:47 ------- This gets weirder and weirder. This works: dmd -c fooA.d fooFoo.d but this does not: dmd -c fooFoo.d fooA.d fooA.d(10): template instance forward reference to template declaration Foo(T) fooA.d(10): Error: Foo!(char) is used as a type The order of files on the compilation line makes a difference?! -- |
July 31, 2007 [Issue 1392] Templates w/ forwd refs fail when in separate modules. | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=1392 ------- Comment #3 from cdunn2001@gmail.com 2007-07-31 16:02 ------- And since this fails: dmd -c fooFoo.d fooA.d(10): template instance forward reference to template declaration Foo(T) fooA.d(10): Error: Foo!(char) is used as a type (and note that the error is listed as being in the other module) it becomes impossible to write an implicit rule in a Makefile. fooFoo.o: fooA.d fooFoo.d %.o: %.d dmd -c $^ make fooFoo.o dmd -c fooFoo.d fooA.d fooA.d(10): template instance forward reference to template declaration Foo(T) fooA.d(10): Error: Foo!(char) is used as a type So I have to add a special rule in my Makefile: fooFoo.o: fooA.d fooFoo.d ${DC} -c $^ in order to get the files listed in the correct order. -- |
July 31, 2007 Re: [Issue 1392] Templates w/ forwd refs fail when in separate modules. | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | Reply to d-bugmail@puremagic.com, > http://d.puremagic.com/issues/show_bug.cgi?id=1392 > > ------- Comment #3 from cdunn2001@gmail.com 2007-07-31 16:02 ------- > And since this fails: > dmd -c fooFoo.d > fooA.d(10): template instance forward reference to template > declaration > Foo(T) > fooA.d(10): Error: Foo!(char) is used as a type > (and note that the error is listed as being in the other module) > it becomes impossible to write an implicit rule in a Makefile. > > fooFoo.o: fooA.d fooFoo.d > %.o: %.d > dmd -c $^ > make fooFoo.o > dmd -c fooFoo.d fooA.d > fooA.d(10): template instance forward reference to template > declaration > Foo(T) > fooA.d(10): Error: Foo!(char) is used as a type > So I have to add a special rule in my Makefile: > > fooFoo.o: fooA.d fooFoo.d > ${DC} -c $^ > in order to get the files listed in the correct order. > have you tried bud or rebuild? http://www.dsource.org/projects/build/ http://www.dsource.org/projects/dsss/wiki/Rebuild |
July 31, 2007 [Issue 1392] Templates w/ forwd refs fail when in separate modules. | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=1392 ------- Comment #5 from cdunn2001@gmail.com 2007-07-31 16:45 ------- Choice of build-tool is a separate issue. I am interested in the command-line. -- |
October 21, 2007 [Issue 1392] Template instantiation fails with circular import | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=1392 smjg@iname.com changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |smjg@iname.com Keywords| |rejects-valid Summary|Templates w/ forwd refs fail|Template instantiation fails |when in separate modules. |with circular import ------- Comment #6 from smjg@iname.com 2007-10-21 11:30 ------- Minimal testcase: ----- bz1392a.d ----- import bz1392b; Foo!(char)* x; ----- bz1392b.d ----- import bz1392a; class Foo(T) {} ---------- Success: dmd bz1392a.d dmd bz1392a.d bz1392b.d Failure: dmd bz1392b.d dmd bz1392b.d bz1392a.d bz1392a.d(3): template instance forward reference to template declaration Foo(T) bz1392a.d(3): Error: Foo!(char) is used as a type -- |
October 29, 2007 [Issue 1392] Template instantiation fails with circular import | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=1392 smjg@iname.com changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |webmaster@villagersonline.co | |m ------- Comment #7 from smjg@iname.com 2007-10-29 08:06 ------- *** Bug 1538 has been marked as a duplicate of this bug. *** -- |
September 18, 2009 [Issue 1392] Template instantiation fails with circular import | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=1392 Rainer Schuetze <r.sagitario@gmx.de> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |r.sagitario@gmx.de --- Comment #8 from Rainer Schuetze <r.sagitario@gmx.de> 2009-09-18 01:48:53 PDT --- I could not reproduce this bug with DMD 1.047 and DMD 2.032. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
September 18, 2009 [Issue 1392] Template instantiation fails with circular import | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=1392 Don <clugdbug@yahoo.com.au> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED CC| |clugdbug@yahoo.com.au Resolution| |FIXED --- Comment #9 from Don <clugdbug@yahoo.com.au> 2009-09-18 15:13:15 PDT --- Still failed in 1.041, but working in 1.047. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation