Created attachment 384
Fix the problem (dmd 2.030)
DMD wrongly mangles template instance name as LName, not TemplateInstanceName:
--------------------
module test;
template Temp() { struct S {} }
pragma(msg, Temp!().S.mangleof);
--------------------
S4test9__T4TempZ1S
--------------------
In the above example, DMD mangles the template instance Temp!() to "9__T4TempZ". Note the preceding number. According to the spec, template instance name should be mangled without preceding number:
--------------------
SymbolName:
LName
TemplateInstanceName
LName:
Number Name
TemplateInstanceName:
__T LName TemplateArgs Z
--------------------
This prevents a name demangler from telling the difference between a usual identifier and template instance name. For example, a demangler can recognize "9__T4TempZ" as a valid module name, not a template instance.
The proposed patch fixes mangle(Declaration *sthis) and TemplateInstance::mangle() (mangle.c).
Comment #1 by rsinfu — 2009-06-01T03:07:57Z
Created attachment 387
Fix the problem (DMD 2.030)
I forgot to deal with TemplateMixin. It should be mangled as LName.
Comment #2 by sean — 2011-08-18T09:14:25Z
The current scheme requires arbitrary lookahead to determine whether a symbol represents a template (see core.demangle.parseSymbolName, for example). If the leading Number were removed then testing for template vs. LName would basically be a matter of checking for a digit vs. underscore. I very much support the idea of eliminating the leading number for template names.
Comment #3 by razvan.nitu1305 — 2019-09-27T08:36:37Z
Just tested on git master and the result is "S4test__T4TempZ1S". Closing as fixed.