Bug 15419 – std.conv.parse() does not accept string literals

Status
RESOLVED
Resolution
WONTFIX
Severity
enhancement
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-12-08T00:32:00Z
Last change time
2016-01-03T14:15:13Z
Assigned to
nobody
Creator
thomas.bockman

Comments

Comment #0 by thomas.bockman — 2015-12-08T00:32:46Z
From the std.conv.parse() unittests: // @@@BUG@@@ the size of China // foreach (i; 2..37) // { // assert(parse!int("0",i) == 0); // assert(parse!int("1",i) == 1); // assert(parse!byte("10",i) == i); // } foreach (i; 2..37) { string s = "0"; assert(parse!int(s,i) == 0); s = "1"; assert(parse!int(s,i) == 1); s = "10"; assert(parse!byte(s,i) == i); } // Same @@@BUG@@@ as above //assert(parse!int("0011001101101", 2) == 0b0011001101101); // assert(parse!int("765",8) == 0765); // assert(parse!int("fCDe",16) == 0xfcde); auto s = "0011001101101"; assert(parse!int(s, 2) == 0b0011001101101); s = "765"; assert(parse!int(s, 8) == octal!765); s = "fCDe"; assert(parse!int(s, 16) == 0xfcde); This is caused by `parse()` using pass-by-ref for the first argument, which does not support rvalues since `scope ref` isn't implemented yet.
Comment #1 by yebblies — 2015-12-08T01:54:15Z
From the description of parse: 'takes the input by reference and advances it to the position following the conversion' This is intentional API design, and therefore not a bug. The compiler used to be very sloppy about what it accepted as an lvalue, so those test cases did work at one point. The workaround is just to use 'to' instead of 'parse', which takes an rvalue argument.
Comment #2 by thomas.bockman — 2015-12-08T03:16:19Z
I'll close this once the unittest has been cleaned up, then. It would still be cool to see this a real fix with `scope ref` some day, though.
Comment #3 by thomas.bockman — 2015-12-08T03:42:10Z
I just realized that you were the one who changed the importance to "enhancement". I thought I had just forgotten to set it initially, since "enhancement" is the default; I wasn't trying to undo your change.
Comment #4 by github-bugzilla — 2015-12-08T04:26:56Z
Commit pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/8da9dbc2ae7a80be15a9cda8e5824cb9501178b1 Merge pull request #3861 from tsbockman/size_of_china Fix Issue 15419 - "@@@BUG@@@ the size of China"
Comment #5 by thomas.bockman — 2015-12-08T04:37:30Z
Marking this as WONTFIX. A real fix would either: 1) Use `scope ref`, if it is ever implemented, or 2) Use the `auto ref` like so (to minimize template bloat): template parse(Target, Source) if(/+constraints+/) { private Target impl(ref Source s) { /+implementation+/ } pragma(inline, true) Target parse(auto ref Source s) { return impl(s); } } The later should completely fix the problem, and be fully backwards compatible. However, it would be a large diff and might confuse ddoc, too.
Comment #6 by github-bugzilla — 2016-01-03T14:15:13Z