D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 10955 - std.getopt errors internally when insufficient arguments are passed
Summary: std.getopt errors internally when insufficient arguments are passed
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2013-09-03 09:24 UTC by Andrej Mitrovic
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 Andrej Mitrovic 2013-09-03 09:24:37 UTC
-----
import std.getopt;

void main(string[] args)
{
    int i;
    getopt(args, &i);
}
-----

std\getopt.d(392): Error: array index [1] is outside array bounds [0 .. 1]
std\getopt.d(401): Error: string slice [2 .. 1] is out of bounds
std\getopt.d(401): Error: cannot return non-void from void function
std\getopt.d(351): Error: template instance std.getopt.getoptImpl!(int*) error instantiating

I think we can fix this easily:

before:
void getopt(T...)(ref string[] args, T opts) {

after:
void getopt(T...)(ref string[] args, T opts) if (T.length > 1) {
Comment 2 basile-z 2016-02-18 08:09:43 UTC
closed by https://github.com/D-Programming-Language/phobos/pull/3859