www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8553] New: templated interface methods (virutal?) and linker missing symbols

reply d-bugmail puremagic.com writes:
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



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
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8553





 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.) -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 16 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8553




PDT ---


 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. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 16 2012