Bug 8553 – templated interface methods (virutal?) and linker missing symbols

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-08-15T13:59:27Z
Last change time
2024-12-13T18:01:03Z
Assigned to
No Owner
Creator
Michal Minich
Moved to GitHub: dmd#18461 →

Comments

Comment #0 by michal.minich — 2012-08-15T13:59:27Z
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.
Comment #1 by k.hara.pg — 2012-08-16T02:21:34Z
(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 code > k.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.)
Comment #2 by michal.minich — 2012-08-16T02:31:46Z
(In reply to comment #1) > (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 code > > > k.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.) 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.
Comment #3 by robert.schadek — 2024-12-13T18:01:03Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18461 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB