D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 17149 - to!int("42", 16, LetterCase.lower) does not compile
Summary: to!int("42", 16, LetterCase.lower) does not compile
Status: RESOLVED INVALID
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-02-06 05:05 UTC by Jonathan M Davis
Modified: 2020-03-21 03:56 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Jonathan M Davis 2017-02-06 05:05:01 UTC
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 basile-z 2017-02-06 07:03:19 UTC
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 Jonathan M Davis 2017-02-06 08:12:46 UTC
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.