Bug 18248 – radix overload of std.conv.parse fails to throw on non-empty range without number
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-01-17T05:40:48Z
Last change time
2019-12-10T08:25:21Z
Keywords
pull
Assigned to
No Owner
Creator
Jonathan M Davis
Comments
Comment #0 by issues.dlang — 2018-01-17T05:40:48Z
Per the documentation for std.conv.parse, parse is supposed to throw if "no character of the input was meaningfully converted." The main overload of parse does this, and the radix overload does if it's given a radix of 10 (since that just calls the main overload) or if the range is empty. However, if you pass it a radix other than 10 and string that is not empty but which does not start with a number, it returns 0 on failure instead of throwing. e.g. this code should throw
----------------
void main()
{
import std.conv;
auto str = ";";
assert(str.parse!uint(16) == 0); // should throw
assert(str == ";");
}
----------------
However, it passes.
Comment #1 by dlang-bot — 2019-12-08T13:17:20Z
@berni44 created dlang/phobos pull request #7310 "Fix Issue 18248 - radix overload of std.conv.parse fails to throw on" fixing this issue:
- Fix Issue 18248 - radix overload of std.conv.parse fails to throw on
non-empty range without number
https://github.com/dlang/phobos/pull/7310
Comment #2 by dlang-bot — 2019-12-10T08:25:21Z
dlang/phobos pull request #7310 "Fix Issue 18248 - radix overload of std.conv.parse fails to throw on" was merged into master:
- 088e55a56a4fd06067165f9a9d9eaf2173a93f73 by Bernhard Seckinger:
Fix Issue 18248 - radix overload of std.conv.parse fails to throw on
non-empty range without number
https://github.com/dlang/phobos/pull/7310