www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15386] New: std.format.formatValue usage hangs

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

          Issue ID: 15386
           Summary: std.format.formatValue usage hangs
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: minor
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: Tachyon165 gmail.com

The set of 'internal' functions in std.format called "formatValue(...)" are not
private, so assuming users should be allowed to call them, consider the
following code:
import std.array, std.format;
auto w = appender!(Char[])();
auto fs = FormatSpec!Char("%.*s");
fs.writeUpToNextSpec(dor);     // dor = DummyOutputRange that eats everything
formatValue(w, 0, fs);

The '*' in the format string means an additional argument would specify the
precision in this case.  When calling std.format.format() or
std.format.formattedWrite() it will usually complain about 'expected int' or
'Range violation' which seems okay - at least it's better than what the code
above does, which appears to hang the program indefinitely.

If the above code is just bad usage and I should use the formattedWrite
interface, then should the other components of std.format be private?

On a similar note: is the format string happens to be compile-time constant, as
it is in this case, shouldn't it be possible to check the variadic arguments
against the string and find the error at compile time?   I suppose it would
need to be a template parameter string.

--
Nov 28 2015