[Issue 4972] New: to!() needs a template constraint

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Oct 1 22:58:45 PDT 2010


http://d.puremagic.com/issues/show_bug.cgi?id=4972

           Summary: to!() needs a template constraint
           Product: D
           Version: unspecified
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: nobody at puremagic.com
        ReportedBy: jmdavisProg at gmx.com


--- Comment #0 from Jonathan M Davis <jmdavisProg at gmx.com> 2010-10-01 22:58:28 PDT ---
The following program

import std.conv;
import std.stdio;

void main()
{
    dchar[7] numStr = "1234567";

    writeln(to!long(numStr));
}


fails compilation with this error

/home/jmdavis/Downloaded_Files/dmd/dmd2/linux/bin/../../src/phobos/std/conv.d(95):
Error: template std.conv.toImpl(T,S) if (!implicitlyConverts!(S,T) &&
isSomeString!(T) && isInputRange!(Unqual!(S)) && isSomeChar!(ElementType!(S)))
toImpl(T,S) if (!implicitlyConverts!(S,T) && isSomeString!(T) &&
isInputRange!(Unqual!(S)) && isSomeChar!(ElementType!(S))) matches more than
one template declaration,
/home/jmdavis/Downloaded_Files/dmd/dmd2/linux/bin/../../src/phobos/std/conv.d(217):toImpl(T,S)
if (isStaticArray!(S)) and
/home/jmdavis/Downloaded_Files/dmd/dmd2/linux/bin/../../src/phobos/std/conv.d(588):toImpl(T,S)
if ((is(S : const(wchar)[]) || is(S : const(dchar)[])) && !isSomeString!(T))
jmdavis at Lyonel ~/Programming/D/datetime [master]$ gvim
/home/jmdavis/Downloaded_Files/dmd/dmd2/src/phobos/std/conv.d


The error gives no indication whatsoever where the actual error is. The problem
is not in to!() but in the code that tried to instantiate to!(), and the error
gives no way to find that code. Ideally, bug # 4970 would be fixed and the
error would correctly indicate where to!() was used, but really, to!() should
have a template constraint of its own. As it stands, it's guaranteed that any
error instantiating to!() is not going to report the actual location of the
error. Copying or moving toImpl!()'s template constraint to to!() would fix the
problem quite easily, and I don't see much reason not to do it. It would
certainly make errors with using to!() easier to fix.

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


More information about the Digitalmars-d-bugs mailing list