Created attachment 388
Patch (DMD 2.030)
=== Problem ===
Under the current spec, a template symbol argument is mangled to an LName:
--------------------
TemplateArg:
T Type // type argument
V Type Value // value argument
S LName // symbol argument
LName:
Number Name
--------------------
This rule is troublesome for demangling. When Name is a QualifiedName (e.g. template symbol), which starts with a Number, then there will be contiguous Numbers in a mangled argument: "S Number Number Name Number Name ...". A demangler will not be able to demangle such input correctly.
For example, this code
--------------------
module test;
struct Temp(alias a) {}
template sym() {}
pragma(msg, Temp!(sym).mangleof);
--------------------
prints "4test20__T4TempS94test3symZ4Temp". Here sym is mangled to "S94test3sym"; the Number is "9" and the Name is "4test3sym". But a demangler will recognize the Number and the Name as "94" and "test3sym", respectively.
=== Proposal ===
A template symbol argument may be
(a) template declaration, template instance, template mixin,
package, module,
(b) variable or function.
(a) is mangled to a QualifiedName and (b) is mangled to a MangledName. These two groups should be treated differently.
My proposal is this:
--------------------
TemplateArg:
S TemplateSymbolArg
TemplateSymbolArg:
QualifiedName // (a) qualified name
M LName // (b) mangled var/func name (_D, _Z, etc.)
--------------------
This grammar does not generate contiguous Numbers. The prefix "M" is necessary to avoid a same-mangled-name collision between QualifiedName and LName.
The attached patch modifies DMD 2.030 so that template symbol argument is mangled with this rule.
Comment #1 by clugdbug — 2009-07-16T08:38:17Z
I don't think problems can ever happen. I solved this ages ago in my compile-time demangler. The demangler knows the length of the string, ("S94test3sym") so it can tell that "94" is impossible as the length; therefore, it must be "9".
I think this bug is probably invalid.