Bug 4972 – to!() needs a template constraint

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
Other
OS
Linux
Creation time
2010-10-01T22:58:00Z
Last change time
2015-06-09T05:15:10Z
Assigned to
andrei
Creator
issues.dlang

Comments

Comment #0 by issues.dlang — 2010-10-01T22:58:28Z
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@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.
Comment #1 by k.hara.pg — 2011-09-09T08:31:43Z