[Issue 4927] writefln silently ignores arguments not present in the format string
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Dec 30 11:57:17 PST 2013
https://d.puremagic.com/issues/show_bug.cgi?id=4927
Stewart Gordon <smjg at iname.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords|accepts-invalid |spec
CC| |smjg at iname.com
Severity|normal |enhancement
--- Comment #6 from Stewart Gordon <smjg at iname.com> 2013-12-30 11:57:11 PST ---
This is actually per spec:
http://dlang.org/phobos/std_format.html
"If there are more remaining arguments than needed by the format specification,
they are ignored but only if at least one argument was formatted."
But I agree that it is a bad design, and that the means of ignoring arguments
should be explicit.
(In reply to comment #2)
> One possibility would be to silently ignore arguments is positional parameters
> are used, and not ignore them otherwise.
I'm not sure. If you're overriding the normal sequence by using positional
arguments, are you showing that you want any unreferenced arguments to be
ignored? Or is it more likely that you have inadvertently left an argument out
of the format string? Moreover, what if you mix positional and non-positional
format specifiers in the same format string?
Maybe what we should do is define %z or something to mean "format as empty
string". It would typically be used in two ways:
- when using non-positional format specifiers, to skip an argument
- when using positional format specifiers, as a dummy reference to an otherwise
unreferenced argument.
(In reply to comment #5)
> In DMD 2.064alpha this program compiles and runs with no errors, warnings or
> run-time exceptions:
>
> import std.stdio;
> void main() {
> writefln("%d %d", 1, 2, 3);
> }
>
> While this gives a run-time exception:
>
> import std.string;
> void main() {
> format("%d %d", 1, 2, 3);
> }
See issue 4532.
> Currently this is accepted (and it prints "A B10"), but I think it should be
> not accepted:
>
> import std.stdio;
> void main() {
> writefln("A%2$s B%1$s", 10);
> }
I agree, this should error.
--
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list