www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 14396] New: compile error std.conv.parse!int with input range

https://issues.dlang.org/show_bug.cgi?id=14396

          Issue ID: 14396
           Summary: compile error std.conv.parse!int with input range
                    (dmd2.067)
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Windows
            Status: NEW
          Severity: regression
          Priority: P1
         Component: DMD
          Assignee: nobody puremagic.com
          Reporter: coz.d.lang gmail.com

import std.stdio;
import std.conv;

void main()
{
    struct StrInputRange
    {
        this (string s) { str = s; }
        char front() const  property { return str[front_index]; }
        char popFront()  property { return str[front_index++]; }
        bool empty() const  property { return str.length <= front_index; }
        size_t        front_index = 0;
        string        str;
    }
    auto input = StrInputRange("777");
    auto a = std.conv.parse!int(input);
    writefln("a = %s", a);
}

/*
-- compile error (dmd2.067)

C:\D\dmd2\windows\bin\..\..\src\phobos\std\conv.d(1992): Error: cannot
implicitly convert expression (cast(int)s.front() - 48) of type int to char
source\app.d(17): Error: template instance std.conv.parse!(int, StrInputRange)
error instantiating

-- output (dmd2.065)

a = 777
*/

--
Apr 02 2015