[Issue 16084] Linker error with interface final function calling virtual function
digitalmars-d-bugs at puremagic.com
Fri May 27 20:38:55 PDT 2016
--- Comment #3 from Vladimir Panteleev <thecybershadow at gmail.com> ---
(In reply to Jack Stouffer from comment #2)
> (In reply to Vladimir Panteleev from comment #1)
> > How can this code be valid?
> According to the spec ;)
It may be syntactically valid but it is semantically useless.
> > You are declaring a templated function with no
> > implementation. Templated functions cannot be virtual. I think this
> > shouldn't even compile.
> If non final template functions aren't possible, then the compiler must
> check for this and the spec needs to be updated.
I think final is implied for template methods.
> I would like to know why this isn't possible though.
Because the compiler must generate a virtual function call table entry for
every instantiation, but it can't do that unless it knows the instantiations
ahead of time (i.e. which template arguments will that template be instantiated
with ANYWHERE in the program). This is something that would only be possible if
the D compiler had access to the source code of the entire program during
compilation, which is not how it works currently (and would preclude partial
compilation to machine code).
More information about the Digitalmars-d-bugs