Thread overview
getopt errors
Jan 21, 2016
Sebastiaan Koppe
Jan 22, 2016
Johannes Pfau
Jan 22, 2016
Sebastiaan Koppe
Jan 22, 2016
Johannes Pfau
Jan 22, 2016
Sebastiaan Koppe
January 21, 2016
This code:

	bool time;
	string fileIn;
	string fileOut;

	auto helpInformation = getopt(
		args,
		"time", "Show timing information", &time,
		"i|input", "Input file (defaults to stdin)", &fileIn,
		"o|output", "Output file (defaults to stdout)", &fileOut
	);

	if (helpInformation.helpWanted)
	{
		defaultGetoptPrinter("ECMAScript 5 minifier.\n\nUsage:\t"~baseName(args[0])~" [OPTIONS]\n\nOptions:\n", helpInformation.options);
		return 1;
	}

on gdc 5.3.0-1 Gives me:

/usr/include/dlang/gdc/std/getopt.d:547:36: error: cannot modify immutable expression *cast(immutable(char)*)receiver
                 if (incremental) ++*receiver;
                                    ^
/usr/include/dlang/gdc/std/getopt.d:548:22: error: cannot modify immutable expression *cast(immutable(char)*)receiver
                 else *receiver = to!(typeof(*receiver))(val);
                      ^
/usr/include/dlang/gdc/std/getopt.d:441:25: error: template instance std.getopt.handleOption!string error instantiating
             handleOption(option, receiver, args, cfg, incremental);
                         ^
/usr/include/dlang/gdc/std/getopt.d:392:22: note: instantiated from here: getoptImpl!(string, string, bool*, string, string, string*, string, string, string*)
     return getoptImpl(args, cfg, opts);
                      ^
source/app.d:24:31: note: instantiated from here: getopt!(string, string, bool*, string, string, string*, string, string, string*)
  auto helpInformation = getopt(
                               ^
/usr/include/dlang/gdc/std/getopt.d:433:33: error: array index [1] is outside array bounds [0 .. 1]
             auto receiver = opts[1];
                                 ^
/usr/include/dlang/gdc/std/getopt.d:442:46: error: string slice [2 .. 1] is out of bounds
             return getoptImpl(args, cfg, opts[2 .. $]);
                                              ^
/usr/include/dlang/gdc/std/getopt.d:442:13: error: cannot return non-void from void function
             return getoptImpl(args, cfg, opts[2 .. $]);
             ^
/usr/include/dlang/gdc/std/getopt.d:442:30: error: template instance std.getopt.getoptImpl!(string*) error instantiating
             return getoptImpl(args, cfg, opts[2 .. $]);
                              ^
/usr/include/dlang/gdc/std/getopt.d:442:30: note: instantiated from here: getoptImpl!(string, string, string*)
             return getoptImpl(args, cfg, opts[2 .. $]);
                              ^
/usr/include/dlang/gdc/std/getopt.d:442:30: note: instantiated from here: getoptImpl!(string, string*, string, string, string*)
             return getoptImpl(args, cfg, opts[2 .. $]);
                              ^
/usr/include/dlang/gdc/std/getopt.d:442:30: note: instantiated from here: getoptImpl!(bool*, string, string, string*, string, string, string*)
             return getoptImpl(args, cfg, opts[2 .. $]);
                              ^
/usr/include/dlang/gdc/std/getopt.d:392:22: note: instantiated from here: getoptImpl!(string, string, bool*, string, string, string*, string, string, string*)
     return getoptImpl(args, cfg, opts);
                      ^
source/app.d:24:31: note: instantiated from here: getopt!(string, string, bool*, string, string, string*, string, string, string*)
  auto helpInformation = getopt(
                               ^
/usr/include/dlang/gdc/std/getopt.d:442:13: error: cannot return non-void from void function
             return getoptImpl(args, cfg, opts[2 .. $]);
             ^
/usr/include/dlang/gdc/std/getopt.d:442:13: error: cannot return non-void from void function
             return getoptImpl(args, cfg, opts[2 .. $]);
             ^
/usr/include/dlang/gdc/std/getopt.d:442:13: error: cannot return non-void from void function
             return getoptImpl(args, cfg, opts[2 .. $]);
             ^
/usr/include/dlang/gdc/std/getopt.d:442:13: error: cannot return non-void from void function
             return getoptImpl(args, cfg, opts[2 .. $]);
             ^
/usr/include/dlang/gdc/std/getopt.d:392:5: error: cannot return non-void from void function
     return getoptImpl(args, cfg, opts);
     ^
source/app.d:33:3: error: undefined identifier defaultGetoptPrinter
   defaultGetoptPrinter("ECMAScript 5 minifier.\n\nUsage:\t"~baseName(args[0])~" [OPTIONS]\n\nOptions:\n", helpInformation.options);
   ^
January 22, 2016
Am Thu, 21 Jan 2016 12:06:18 +0000
schrieb Sebastiaan Koppe <mail@skoppe.eu>:

> This code:
> 
> 	bool time;
> 	string fileIn;
> 	string fileOut;
> 
> 	auto helpInformation = getopt(
> 		args,
> 		"time", "Show timing information", &time,
> 		"i|input", "Input file (defaults to stdin)", &fileIn,
> 		"o|output", "Output file (defaults to stdout)",
> &fileOut );
> 
> 	if (helpInformation.helpWanted)
> 	{
> 		defaultGetoptPrinter("ECMAScript 5
> minifier.\n\nUsage:\t"~baseName(args[0])~"
> [OPTIONS]\n\nOptions:\n", helpInformation.options);
> 		return 1;
> 	}
> 

defaultGetoptPrinter is not yet available in the phobos version used by GDC. GDC uses phobos version 2.066, defaultGetoptPrinter was added in 2.067.
January 22, 2016
On Friday, 22 January 2016 at 10:06:01 UTC, Johannes Pfau wrote:
> defaultGetoptPrinter is not yet available in the phobos version used by GDC. GDC uses phobos version 2.066, defaultGetoptPrinter was added in 2.067.

Thanks. I never know which version of this supports which version of that. Any easy way of checking this? I mean, how can I tell that gdc 5.3.0-1 supports phobos 2.066?

I reckon other people run into these errors as well, and it would be nice if there was a way of checking whether a function is supported in gdc/ldc x.x.x Hmm. Sounds like a nice project with git, libdparse and vibe.

What about the other errors though?
January 22, 2016
Am Fri, 22 Jan 2016 11:32:30 +0000
schrieb Sebastiaan Koppe <mail@skoppe.eu>:

> On Friday, 22 January 2016 at 10:06:01 UTC, Johannes Pfau wrote:
> > defaultGetoptPrinter is not yet available in the phobos version used by GDC. GDC uses phobos version 2.066, defaultGetoptPrinter was added in 2.067.
> 
> Thanks. I never know which version of this supports which version of that. Any easy way of checking this? I mean, how can I tell that gdc 5.3.0-1 supports phobos 2.066?
> 

The best way is running this code snippet:
---------------------------------------------------
import std.compiler;
import std.stdio;

void main()
{
    writefln("%s %s %s.%s (D%s)", name, vendor,
        version_major,
        version_minor, D_major);
}
---------------------------------------------------
You can also have a look at the std.compiler implementation if you want to use the __VERSION__ and __VENDOR__ variables directly.

> I reckon other people run into these errors as well, and it would be nice if there was a way of checking whether a function is supported in gdc/ldc x.x.x Hmm. Sounds like a nice project with git, libdparse and vibe.

Yes, this is really a common problem. I'd say the simplest way to check is trying to compile the code with the matching DMD version (e.g. 2.066.1).

> What about the other errors though?

Same reason. The old getopt code can't handle the help strings and therefore produces these error messages. This works:

---------------------------------------------------
import std.getopt;
void main(string[] args)
{
	bool time;
	string fileIn;
	string fileOut;

	getopt(
		args,
		"time", &time,
		"i|input", &fileIn,
		"o|output", &fileOut
	);
}
January 22, 2016
On Friday, 22 January 2016 at 13:03:58 UTC, Johannes Pfau wrote:
> Am Fri, 22 Jan 2016 11:32:30 +0000
> schrieb Sebastiaan Koppe <mail@skoppe.eu>:
>> Thanks. I never know which version of this supports which version of that. Any easy way of checking this? I mean, how can I tell that gdc 5.3.0-1 supports phobos 2.066?
>> 
> The best way is running this code snippet:
> ---------------------------------------------------
> import std.compiler;
> import std.stdio;
>
> void main()
> {
>     writefln("%s %s %s.%s (D%s)", name, vendor,
>         version_major,
>         version_minor, D_major);
> }
> ---------------------------------------------------

Why doesn't gdc emit this when called with `--version`?

> Yes, this is really a common problem. I'd say the simplest way to check is trying to compile the code with the matching DMD version (e.g. 2.066.1).

When I have nothing to do I might setup a service that tells you in which version a symbol was introduced.

>> What about the other errors though?
>
> Same reason. The old getopt code can't handle the help strings and therefore produces these error messages.

I see, I was mislead due to the errors being in the std code.