The following code causes the error: -------------------- import std.getopt; void main() { int[string] foo; auto args = ["", "-t", "a=1"]; getopt(args, "t", &foo); } -------------------- core.exception.RangeError@std.getopt(519): Range violation -------------------- There is no error if bundling is turned on: getopt(args, config.bundling, "t", &foo); There is no error if the option contains more than one letter e.g. "--tune"
The bug is found! In std/getopt.d: If the option is not long and bundling is forbidden lines 587-588 are executed. If arg looks like "-t" value is empty but !value is false, i.e. in the following code all asserts are true: test.d: -------------------- void main() { string s = "t"; string s1 = s[1..$]; string s2 = null; assert(s1 == null); assert(s2 == null); assert(!s1 == false); // Why? assert(!s2 == true); } -------------------- Hence in std/getopt.d in the line 464: !val is false and val is empty when we come to line 519 and try to access its contents. I'm going to fix it right now. But the behavior of empty slices looks like a bug of the compiler.
https://github.com/D-Programming-Language/phobos/pull/315 https://github.com/D-Programming-Language/phobos/commit/0ee6a1afbd8686a8051af4c86df9333c22daec89