digitalmars.D.bugs - [Issue 8553] New: templated interface methods (virutal?) and linker missing symbols
- d-bugmail puremagic.com (58/58) Aug 15 2012 http://d.puremagic.com/issues/show_bug.cgi?id=8553
- d-bugmail puremagic.com (13/16) Aug 16 2012 http://d.puremagic.com/issues/show_bug.cgi?id=8553
- d-bugmail puremagic.com (11/27) Aug 16 2012 http://d.puremagic.com/issues/show_bug.cgi?id=8553
http://d.puremagic.com/issues/show_bug.cgi?id=8553 Summary: templated interface methods (virutal?) and linker missing symbols Product: D Version: D2 Platform: All OS/Version: All Status: NEW Severity: normal Priority: P2 Component: DMD AssignedTo: nobody puremagic.com ReportedBy: michal.minich gmail.com --- Comment #0 from Michal Minich <michal.minich gmail.com> 2012-08-15 13:59:27 PDT --- module main; class Visitor (T) { void visit (KlazzDeriv) { } } interface IKlazz { void accept (R) (Visitor!(R)); } abstract class Klazz : IKlazz { // uncomment this to get "non-virtual functions cannot be abstract" // abstract void accept (R) (Visitor!(R)); // uncomment this line to compile // void accept (R) (Visitor!(R) v) { } } class KlazzDeriv : Klazz { void accept (R) (Visitor!(R) v) { v.visit(this); } } void main () { // change Klazz to KlazzDeriv and it compiles Klazz k = new KlazzDeriv; // is accept virtual call ? is it supported for templated interface methods ? k.accept (new Visitor!int); } dmd 2.060 on both systems On 64 bit linux main.o: In function `_Dmain': main.d:25: undefined reference to `_D4main6IKlazz13__T6acceptTiZ6acceptMFC4main14__T7VisitorTiZ7VisitorZv' collect2: error: ld returned 1 exit status on 32 bit win xp OPTLINK (R) for Win32 Release 8.00.12 Copyright (C) Digital Mars 1989-2010 All rights reserved. http://www.digitalmars.com/ctg/optlink.html main.obj(main) Error 42: Symbol Undefined _D4main6IKlazz13__T6acceptTiZ6acceptMFC4main14__T7VisitorTiZ7VisitorZv --- errorlevel 1 demangled missing symbol is void main.IKlazz.accept!(int).accept(main.Visitor!(int).Visitor) are currently templated virutal members supprted? Anyway ... it should not result in linker error. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 15 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8553 --- Comment #1 from Kenji Hara <k.hara.pg gmail.com> 2012-08-16 02:21:34 PDT --- (In reply to comment #0)are currently templated virutal members supprted? Anyway ... it should not result in linker error.Today, you can declare template function in interface, but it is treated as final implicitly. Because template function cannot be virtual. So, in the codek.accept (new Visitor!int);IKlazz.accept is always called instead of KlazzDeriv.accept, but its implementation is not there, so linker error occurs. Therefore, this is not a bug, but compiler should more better error message. (I think compiler should enforce adding 'final' keyword to IKlazz.accept.) -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 16 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8553 --- Comment #2 from Michal Minich <michal.minich gmail.com> 2012-08-16 02:31:46 PDT --- (In reply to comment #1)(In reply to comment #0)Also it seems that templated methods in abstract class are treated as final implicitly. But there is, at least, little bit cryptic message "non-virtual functions cannot be abstract". So it seems the compiler applies hidden "final" attribute an the method declaration. I think compiler should enforce explicit "final" attribute to be declared by user on the method. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------are currently templated virutal members supprted? Anyway ... it should not result in linker error.Today, you can declare template function in interface, but it is treated as final implicitly. Because template function cannot be virtual. So, in the codek.accept (new Visitor!int);IKlazz.accept is always called instead of KlazzDeriv.accept, but its implementation is not there, so linker error occurs. Therefore, this is not a bug, but compiler should more better error message. (I think compiler should enforce adding 'final' keyword to IKlazz.accept.)
Aug 16 2012