D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 2861 - Forward reference of .stringof in a template gives wrong value
Summary: Forward reference of .stringof in a template gives wrong value
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: wrong-code
Depends on:
Blocks: 340
  Show dependency treegraph
 
Reported: 2009-04-20 04:53 UTC by Don
Modified: 2014-04-18 09:12 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Don 2009-04-20 04:53:29 UTC
If you reverse the order of the declaration of x and Type, it works correctly.
For D2, change declaration of x to:  enum x = Type.stringof;
This is very similar to bug 934. With my patch applied, the equivalent situation for .mangleof works correctly.
----
template Templ(T) {
   const char[] x = Type.stringof;
   alias T Type;
}

void main() {
    static assert(Templ!(int).x =="int");
}
Comment 1 Don 2009-08-31 07:57:51 UTC
Fixed DMD2.030 and 1.045.
This works now.
Test case was wrong, though, should have been:
--
template Templ(T) {
   const char[] x = (Type).stringof;
   alias T Type;
}

void main() {
    static assert(Templ!(int).x =="int");
}