digitalmars.D.bugs - [Issue 1392] New: Templates w/ forwd refs fail when in separate modules.
- d-bugmail puremagic.com (78/78) Jul 31 2007 http://d.puremagic.com/issues/show_bug.cgi?id=1392
- d-bugmail puremagic.com (9/9) Jul 31 2007 http://d.puremagic.com/issues/show_bug.cgi?id=1392
- d-bugmail puremagic.com (10/10) Jul 31 2007 http://d.puremagic.com/issues/show_bug.cgi?id=1392
- d-bugmail puremagic.com (22/22) Jul 31 2007 http://d.puremagic.com/issues/show_bug.cgi?id=1392
- BCS (4/31) Jul 31 2007 have you tried bud or rebuild?
- d-bugmail puremagic.com (4/4) Jul 31 2007 http://d.puremagic.com/issues/show_bug.cgi?id=1392
- d-bugmail puremagic.com (27/27) Oct 21 2007 http://d.puremagic.com/issues/show_bug.cgi?id=1392
- d-bugmail puremagic.com (9/9) Oct 29 2007 http://d.puremagic.com/issues/show_bug.cgi?id=1392
- d-bugmail puremagic.com (10/10) Sep 18 2009 http://d.puremagic.com/issues/show_bug.cgi?id=1392
- d-bugmail puremagic.com (12/12) Sep 18 2009 http://d.puremagic.com/issues/show_bug.cgi?id=1392
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.
--
Jul 31 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1392
cdunn2001 gmail.com changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |cdunn2001 gmail.com
Oh, I should add that separate module compilation works fine when Foo is not a
template.
--
Jul 31 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1392 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?! --
Jul 31 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1392
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.
--
Jul 31 2007
Reply to d-bugmail puremagic.com,
http://d.puremagic.com/issues/show_bug.cgi?id=1392
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
Jul 31 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1392 Choice of build-tool is a separate issue. I am interested in the command-line. --
Jul 31 2007
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
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
--
Oct 21 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1392
smjg iname.com changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |webmaster villagersonline.co
| |m
*** Bug 1538 has been marked as a duplicate of this bug. ***
--
Oct 29 2007
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
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: -------
Sep 18 2009
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
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: -------
Sep 18 2009









d-bugmail puremagic.com 