Bug 10841 – std.conv.parse failed when parsing a slice string
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2013-08-17T18:14:00Z
Last change time
2013-08-17T18:51:09Z
Assigned to
nobody
Creator
bitworld
Comments
Comment #0 by bitworld — 2013-08-17T18:14:55Z
The test code is here:
//=============
string s1 = "11AB";
auto r = parse!int(s1[0..2], 16);
//=============
It worked with DMD 2.062, but failed with DMD 2.063.2.
Comment #1 by issues.dlang — 2013-08-17T18:42:41Z
If it worked with 2.062, it was a bug. parse accepts its argument by ref (because it alters the argument by popping characters off of it as they're parsed), which means that the argument must be an lvalue, and a slice is not an lvalue.
Comment #2 by andrej.mitrovich — 2013-08-17T18:51:09Z
The rationale of the change is in the changelog:
http://dlang.org/changelog.html#sliceref
As a workaround you'll have to assign s1[0..2] to another variable and pass it to parse. A better alternative is to use to!() instead of parse!():
string s1 = "11AB";
auto r = to!int(s1[0..2], 16);
There /was/ some brief discussion about making parse work with slices as well, since it could be considered convenient (and would avoid code breakage), but there was no outcome for the 2.063 release.