[Issue 18172] std.getopt should allow taking parameters by `ref` (like std.format.formattedRead), s.t. it can be used in @safe

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Mar 15 16:29:00 UTC 2018


https://issues.dlang.org/show_bug.cgi?id=18172

--- Comment #8 from Jonathan M Davis <issues.dlang at jmdavisProg.com> ---
(In reply to Jack Stouffer from comment #7)
> I should have emphized more the fact that I had already modified getopt.
> I've attached my changes as a patch

Without compiling with -dip1000, nothing will be fixed, and Phobos isn't
compiled with -dip1000, so the unit tests don't tell us anything. If I test
your changes locally (minus the unit test changes) and compile your example in
a separate program compiled with -dip1000, then I get this error:

q.d(9): Error: @safe function D main cannot call @system function
std.getopt.getopt!(string, string, bool*, string, string, bool*).getopt

which indicates that the signature for getopt works just fine at that point,
making the caller @safe. It's just that getopt's internals still need some
fixing.

If I slap @trusted on getopt to make it shut up, then I get linker errors about
stuff in std.conv being undefined, but there are no more errors from the
compiler itself. I think that that happens sometimes when some code is compiled
with -dip1000 and some without, but I'm not sure. Unfortunately, Phobos as a
whole does not work with -dip1000 yet, and I haven't done much with -dip1000.
But from the looks of it, I'd say that it looks likely that we can fix getopt
to be @safe with -dip1000 and scope without breaking the API. There may turn
out to be bugs there that Walter will need to fix to get it fully working, but
it looks promising.

Either way, you can't update the unit tests right now to be @safe, because
Phobos isn't compiled with -dip1000.

--


More information about the Digitalmars-d-bugs mailing list