Bug 17149 – to!int("42", 16, LetterCase.lower) does not compile

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-02-06T05:05:01Z
Last change time
2020-03-21T03:56:42Z
Assigned to
No Owner
Creator
Jonathan M Davis

Comments

Comment #0 by issues.dlang — 2017-02-06T05:05:01Z
This code does not compile. void main() { import std.ascii; import std.conv; assert(to!int("42", 16) == 0x42); assert(to!int("42", 16, LetterCase.lower) == 0x42); assert(to!int("42", 16, LetterCase.upper) == 0x42); } The first to!int call works, but the other two do not. It is clear from the documentation for std.conv.to that they should. And std.conv.to has this in its unit tests: assert(to!string(Int(0x1234BCD), 16u, LetterCase.upper) == "1234BCD"); assert(to!string(Int(0x1234AF), 16u, LetterCase.lower) == "1234af"); So, the problem is likely related to access levels in some way, with required functions probably being private. Regardless, the results is that you can't currently give std.conv.to!int a LetterCase argument, forcing all hex literals to be uppercase. It wouldn't surprise me if this is a regression, but I'm not in a good position to test that at the moment.
Comment #1 by b2.temp — 2017-02-06T07:03:19Z
The letter case is only interesting in the "int2string" way. I don't see the point of allowing it as parameter in the "string2int" way. The "string2int" way handles mixed lower and upper case. void main() { import std.ascii; import std.conv; assert(to!int("AbCde", 16) == 0xabcde); assert(to!int("aBcdE", 16) == 0xabcde); }
Comment #2 by issues.dlang — 2017-02-06T08:12:46Z
Hmmm. Well, when I read the documentation, I understood that you had to specify upper or lowercase and not that it accepted both. Rereading through the documentation though, I see that it's talking specifically about converting _from_ int to string rather than the other way around. So, I guess that I misread the documentation.