www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2066] New: toString(int) nto CTFE-compatible

reply d-bugmail puremagic.com writes:
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"


-- 
May 04 2008
next sibling parent BCS <ao pathlink.com> writes:
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.
May 04 2008
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2066







 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. --
May 04 2008
prev sibling next sibling parent "Janice Caron" <caron800 googlemail.com> writes:
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));
May 04 2008
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2066






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));
}


-- 
Nov 23 2008
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2066


Andrei Alexandrescu <andrei metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|                            |andrei metalanguage.com
         AssignedTo|nobody puremagic.com        |andrei metalanguage.com


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 11 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2066


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug yahoo.com.au
            Summary|toString(int) nto           |to!(string)(int) into
                   |CTFE-compatible             |CTFE-compatible



Changed bug title to reflect changes in Phobos: toString -> to!(string).
Fixed in svn 1402. Requires DMD svn 332 or later.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 18 2010
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2066


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
                 CC|                            |bugzilla digitalmars.com
         Resolution|                            |FIXED



22:44:16 PST ---
fixed dmd 2.040

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 30 2010