www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10841] New: std.conv.parse failed when parsing a slice string

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10841

           Summary: std.conv.parse failed when parsing a slice string
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: bitworld qq.com


--- Comment #0 from Heromyth <bitworld qq.com> 2013-08-17 18:14:55 PDT ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 17 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10841


Jonathan M Davis <jmdavisProg gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |jmdavisProg gmx.com
         Resolution|                            |INVALID


--- Comment #1 from Jonathan M Davis <jmdavisProg gmx.com> 2013-08-17 18:42:41
PDT ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 17 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10841


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich gmail.com


--- Comment #2 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-08-17
18:51:09 PDT ---
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.

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