Bug 10956 – std.getopt error on wrongly position arguments should improve

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-09-03T09:30:22Z
Last change time
2020-03-21T03:56:33Z
Assigned to
No Owner
Creator
Andrej Mitrovic

Comments

Comment #0 by andrej.mitrovich — 2013-09-03T09:30:22Z
----- import std.getopt; void main(string[] args) { int i; getopt(args, &i, ""); } ----- This call is wrong, the text argument should come before the pointer, but the diagnostics are bad: std\getopt.d(499): Deprecation: using * on an array is deprecated; use *(receiver).ptr instead std\getopt.d(499): Error: cannot modify immutable expression *cast(immutable(char)*)receiver std\getopt.d(500): Deprecation: using * on an array is deprecated; use *(receiver).ptr instead std\getopt.d(500): Deprecation: using * on an array is deprecated; use *(receiver).ptr instead std\getopt.d(500): Error: cannot modify immutable expression *cast(immutable(char)*)receiver std\getopt.d(400): Error: template instance std.getopt.handleOption!string error instantiating std\getopt.d(351): instantiated from here: getoptImpl!(int*, string) test.d(8): instantiated from here: getopt!(int*, string) std\getopt.d(351): Error: template instance std.getopt.getoptImpl!(int*, string) error instantiating test.d(8): instantiated from here: getopt!(int*, string) test.d(8): Error: template instance std.getopt.getopt!(int*, string) error instantiating
Comment #1 by b2.temp — 2015-11-27T17:11:14Z
diagnostic has changed but still bad. The variadic args in getoptImpl(T...) could be statically checked, even index: must be string, odd index: must be pointer.
Comment #2 by b2.temp — 2015-12-01T13:25:24Z
(In reply to Andrej Mitrovic from comment #0) > ----- > import std.getopt; > > void main(string[] args) > { > int i; > getopt(args, &i, ""); > } > ----- > > This call is wrong, the text argument should come before the pointer, but > the diagnostics are bad: > > std\getopt.d(499): Deprecation: using * on an array is deprecated; use > *(receiver).ptr instead > std\getopt.d(499): Error: cannot modify immutable expression > *cast(immutable(char)*)receiver > std\getopt.d(500): Deprecation: using * on an array is deprecated; use > *(receiver).ptr instead > std\getopt.d(500): Deprecation: using * on an array is deprecated; use > *(receiver).ptr instead > std\getopt.d(500): Error: cannot modify immutable expression > *cast(immutable(char)*)receiver > std\getopt.d(400): Error: template instance std.getopt.handleOption!string > error instantiating > std\getopt.d(351): instantiated from here: getoptImpl!(int*, string) > test.d(8): instantiated from here: getopt!(int*, string) > std\getopt.d(351): Error: template instance std.getopt.getoptImpl!(int*, > string) error instantiating > test.d(8): instantiated from here: getopt!(int*, string) > test.d(8): Error: template instance std.getopt.getopt!(int*, string) error > instantiating I'll probably propose something in the next weeks. I've currently designed a template that works in the constraint, however it misses a special case (option passed for next param): http://dpaste.dzfl.pl/b8d1fb991482 Anyway, quite faisable...
Comment #3 by b2.temp — 2015-12-06T01:58:27Z
(In reply to bb.temp from comment #2) > (In reply to Andrej Mitrovic from comment #0) > > ----- > Anyway, quite faisable... done: https://github.com/BBasile/phobos/blob/ce4c33ed68ae7a1131a5b45c1ddae47c1f391d5c/std/getopt.d#L537-L610 http://dpaste.dzfl.pl/85c70ecd3ddd all the existing unittests pass.
Comment #4 by b2.temp — 2016-02-18T08:08:15Z