Bug 3043 – Template symbol arg cannot be demangled

Status
RESOLVED
Resolution
WONTFIX
Severity
minor
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2009-06-01T03:48:00Z
Last change time
2015-06-30T15:14:19Z
Keywords
patch, spec
Assigned to
bugzilla
Creator
rsinfu
Blocks
14576, 3104

Attachments

IDFilenameSummaryContent-TypeSize
388fix_mangletiargsym.patchPatch (DMD 2.030)text/plain471

Comments

Comment #0 by rsinfu — 2009-06-01T03:48:14Z
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.
Comment #2 by bugzilla — 2010-11-09T22:57:21Z
http://www.dsource.org/projects/dmd/changeset/745 Fixing this would break binary compatibility and all the existing demanglers.
Comment #3 by hsteoh — 2015-06-30T15:14:19Z