[Issue 9797] to!int() cannot convert hexadecimal numbers

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Fri Nov 6 04:44:03 PST 2015


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

Cauterite <cauterite at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |cauterite at gmail.com

--- Comment #3 from Cauterite <cauterite at gmail.com> ---
I can see only one reasonable(ish) solution here:
Patch toImpl() to detect prefixes like "0x" and "0b", so it calls parse() with
the appropriate radix. This may not be as much of a problem as patching parse()
itself, since toImpl() either parses the whole input successfully or throws.

However, if the caller is not fully aware that to() accepts these alternative
number syntaxes, it could easily cause subtle bugs. Additionally, having
parse() and to() operate differently doesn't sit right with me.

The only other option I can think of would be to provide a separate function
specifically for parsing D-style numeric literals, but this is out of the scope
of std.conv

Unless anyone has a better idea, I suggest WONTFIX. It's not an *especially*
common problem, and parse() with explicit radix makes it trivial for callers to
deal with it themselves.

--


More information about the Digitalmars-d-bugs mailing list