Bug 6954 – std.conv.to!int doesn't work in CTFE

Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-11-15T11:39:00Z
Last change time
2011-11-16T05:28:18Z
Assigned to
nobody
Creator
dlang-bugzilla

Comments

Comment #0 by dlang-bugzilla — 2011-11-15T11:39:54Z
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 by clugdbug — 2011-11-16T05:21:17Z
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 by dlang-bugzilla — 2011-11-16T05:28:18Z
Right, should have updated before reporting. Sorry for the noise.