import std.string; pragma(msg, toString(42)); The above program fails to compile, with the error message "cannot evaluate toString(42) at compile time"
Reply to d-bugmail@puremagic.com, > http://d.puremagic.com/issues/show_bug.cgi?id=2066 > > Summary: toString(int) nto CTFE-compatible > Product: D > Version: 2.014 > Platform: PC > OS/Version: Windows > Status: NEW > Severity: major > Priority: P2 > Component: Phobos > AssignedTo: bugzilla@digitalmars.com > ReportedBy: simen.kjaras@gmail.com > import std.string; > > pragma(msg, toString(42)); > > The above program fails to compile, with the error message "cannot > evaluate toString(42) at compile time" > in "static code" you can use "42.stringof" but, IIRC, that won't work in other CTFE functions.
(In reply to comment #1) > Reply to d-bugmail@puremagic.com, > in "static code" you can use "42.stringof" but, IIRC, that won't work in > other CTFE functions. Example: template foo(int line = __LINE__) { pragma(msg, line.stringof); // prints 'line'. pragma(msg, toString(line)); // should print a number of some kind. Currently does not. } That is pretty much why I need this.
On 04/05/2008, d-bugmail@puremagic.com <d-bugmail@puremagic.com> wrote: > import std.string; > > pragma(msg, toString(42)); > > The above program fails to compile, with the error message "cannot evaluate > toString(42) at compile time" You could try import std.metastrings; pragma(msg, ToString!(42));
Thanks for the workaround, Janice. Here is another example that is almost certainly related (CTFE seems to work only with single-digit numbers!): import std.stdio; import std.string; template Foo(uint id) { invariant string Foo = "writefln(" ~ std.string.toString(id) ~ ");"; } invariant uint ID = 1; // THIS LINE WORKS //invariant uint ID = 10; // THIS LINE FAILS void main() { mixin(Foo!(ID)); }
Changed bug title to reflect changes in Phobos: toString -> to!(string). Fixed in svn 1402. Requires DMD svn 332 or later.
fixed dmd 2.040