Thread overview
[Issue 6954] New: std.conv.to!int doesn't work in CTFE
Nov 15, 2011
Vladimir Panteleev
Nov 16, 2011
Don
Nov 16, 2011
Vladimir Panteleev
November 15, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6954

           Summary: std.conv.to!int doesn't work in CTFE
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: minor
          Priority: P2
         Component: Phobos
        AssignedTo: nobody@puremagic.com
        ReportedBy: thecybershadow@gmail.com


--- Comment #0 from Vladimir Panteleev <thecybershadow@gmail.com> 2011-11-15 11:39:54 PST ---
The reason it doesn't work is scope(exit).

Looking at the code[1], it doesn't look like the scope(exit) is really
necessary here (I don't see why it should catch exceptions thrown by parse), so
until there's scope(...) CTFE support, a simple fix would be to rewrite the
code as:

    auto result = parse!T(v);
    if (v.length)
        convError!(SV, T)(v);
    return result;

[1]: https://github.com/D-Programming-Language/phobos/blob/master/std/conv.d#L1606

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 16, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6954


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug@yahoo.com.au


--- Comment #1 from Don <clugdbug@yahoo.com.au> 2011-11-16 05:21:17 PST ---
Do you have a test case that doesn't work?
scope statements are supported in CTFE now.
This works on git DMD head:

import std.conv;
static assert(to!int("754") == 754);

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 16, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6954


Vladimir Panteleev <thecybershadow@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


--- Comment #2 from Vladimir Panteleev <thecybershadow@gmail.com> 2011-11-16 05:28:18 PST ---
Right, should have updated before reporting. Sorry for the noise.

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