Bug 1168 – Passing a .stringof of an expression as a template value parameter results in the string of the type
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2007-04-20T07:12:00Z
Last change time
2014-02-16T15:22:03Z
Keywords
patch, wrong-code
Assigned to
nobody
Creator
matti.niemenmaa+dbugzilla
Comments
Comment #0 by matti.niemenmaa+dbugzilla — 2007-04-20T07:12:58Z
(Set version as 1.012, since 1.013 wasn't in the list yet.)
template T(char[] s) {
const char[] T = s;
}
char[] f(char[] s) {
return s;
}
void main() {
int foo;
assert (foo.stringof == f(foo.stringof)); // works
assert (foo.stringof == T!(foo.stringof)); // fails
}
T!(foo.stringof) results in "int", it should be "foo".
Comment #1 by matti.niemenmaa+dbugzilla — 2007-09-01T03:49:01Z
*** Bug 1465 has been marked as a duplicate of this bug. ***
Comment #2 by jeremiep — 2009-09-05T13:47:22Z
The following patch to mtype.c fix the issue:
--- ..\src\orig\mtype.cpp Thu Sep 03 01:01:40 2009
+++ ..\src\dmd\mtype.cpp Sat Sep 05 16:42:50 2009
@@ -4530,6 +4530,11 @@
goto Lerror;
goto L3;
}
+ else if(v && id == Id::stringof) {
+ e = new DsymbolExp(loc, s, 0);
+ *pe = new DotIdExp(loc, e, id);
+ return;
+ }
t = s->getType();
if (!t && s->isDeclaration())
t = s->isDeclaration()->type;
It turns out stringof was applied on the type of the Dsymbol, not the symbol itself.
Comment #3 by clugdbug — 2009-09-07T00:37:21Z
Cool! Add 'patch' to the list of keywords when you've submitted a patch, it makes them easier to track.