Bug 18906 – Template specialisations should not be stripped if they're not called

Status
RESOLVED
Resolution
INVALID
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Windows
Creation time
2018-05-25T07:49:56Z
Last change time
2018-11-26T07:29:12Z
Keywords
C++, industry
Assigned to
No Owner
Creator
Manu

Comments

Comment #0 by turkeyman — 2018-05-25T07:49:56Z
extern(C++) class C { T t(T)(T x); int t(T : int)(int x) { return x * 2; } } Given the code above, the symbol `t!int` will NOT be emit to the object unless something somewhere calls that instantiation. I think this is wrong, an explicit specialisation like this needs to go in the object file regardless, it was hand-written, and it might be used externally (in my case, it is used externally). Likewise, we should have a method to force an instantiation of a template into the object like C++ has. For instance, C++ for the above: `template float C::t<float>(float);` Causes explicit instantiation of the template for float. Perhaps D already has this syntax, but I don't know what it is?
Comment #1 by n8sh.secondary — 2018-05-25T17:46:44Z
``` int t(T : int)(int x) { return x * 2; } ``` What is the point of the template?
Comment #2 by turkeyman — 2018-05-25T17:54:54Z
It's a specialisation. Someone might call `t!(IDontKnowWhat)(value);`, and if IDontKnowWhat is int, it should use that specialisation, and if it's not, it should instantiate the generic unspecialised one. It also affects function mangling, and extern linkage.
Comment #3 by turkeyman — 2018-09-16T20:06:36Z
This is actually pretty problematic issue...
Comment #4 by razvan.nitu1305 — 2018-11-18T11:19:39Z
Why is this problematic? That is a template specialization for types that convert to int so adding the symbol t!int to the object file would not be very accurate.
Comment #5 by turkeyman — 2018-11-18T18:59:40Z
Sorry, it should probably be '=', not ':'...
Comment #6 by turkeyman — 2018-11-18T18:59:59Z
But you get the idea...