D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6954 - std.conv.to!int doesn't work in CTFE
Summary: std.conv.to!int doesn't work in CTFE
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P2 minor
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-11-15 11:39 UTC by Vladimir Panteleev
Modified: 2011-11-16 05:28 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 Vladimir Panteleev 2011-11-15 11:39:54 UTC
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
Comment 1 Don 2011-11-16 05:21:17 UTC
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);
Comment 2 Vladimir Panteleev 2011-11-16 05:28:18 UTC
Right, should have updated before reporting. Sorry for the noise.