After calling clear() on a std.array.Appender, formattedWrite() using that appender fails silently. Calling the appender's put() method once after a clear() is a workaround. Tested on DMD 2.062. Example: ---- import std.stdio, std.array, std.format, std.string; void main() { // FIRST EXAMPLE: use only put(). auto a = appender!string; a.put( format("%d", 1) ); writeln(a.data); a.clear(); // put() after clear() is OK. a.put( format("%d", 2) ); writeln(a.data); assert(a.data == "2"); // SECOND EXAMPLE: use only formattedWrite(). auto b = appender!string; b.reserve(128); formattedWrite(b, "%d", 1); writeln(b.data); assert(b.data == "1"); b.clear(); // formattedWrite() after clear() does not work. formattedWrite(b, "%d", 2); // <-- FAILS SILENTLY writeln(b.data); // "" (writes empty string) assert(b.data == ""); // this should not pass, but it does. // You have to call put() on appender before formattedWrite() works again. b.put(""); formattedWrite(b, "%d", 3); writeln(b.data); assert(b.data == "3"); } ----
https://github.com/D-Programming-Language/phobos/pull/2141 As was noted it was object.d's clear being called via UFCS.
This currently correctly fails to compile, and a note has been added to the documentation. Shouldn't this be closed?
(In reply to yazan.dabain from comment #2) > This currently correctly fails to compile, and a note has been added to the > documentation. Shouldn't this be closed? Yup