Bug 2066 – to!(string)(int) into CTFE-compatible

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2008-05-04T15:59:00Z
Last change time
2015-06-09T01:21:35Z
Assigned to
andrei
Creator
simen.kjaras
Depends on
3556

Comments

Comment #0 by simen.kjaras — 2008-05-04T15:59:04Z
import std.string; pragma(msg, toString(42)); The above program fails to compile, with the error message "cannot evaluate toString(42) at compile time"
Comment #1 by lovesyao — 2008-05-04T16:20:31Z
Reply to [email protected], > 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: [email protected] > ReportedBy: [email protected] > 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.
Comment #2 by simen.kjaras — 2008-05-04T16:32:13Z
(In reply to comment #1) > Reply to [email protected], > 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.
Comment #3 by caron800 — 2008-05-04T16:58:12Z
On 04/05/2008, [email protected] <[email protected]> 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));
Comment #4 by rosscanning2007 — 2008-11-24T00:23:47Z
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)); }
Comment #5 by clugdbug — 2010-01-18T00:59:38Z
Changed bug title to reflect changes in Phobos: toString -> to!(string). Fixed in svn 1402. Requires DMD svn 332 or later.
Comment #6 by bugzilla — 2010-01-30T22:44:16Z
fixed dmd 2.040