Bug 10291 – formattedWrite() to an Appender fails silently after Appender.clear()

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-06-07T14:19:00Z
Last change time
2016-06-27T20:00:43Z
Keywords
pull
Assigned to
nobody
Creator
jared

Comments

Comment #0 by jared — 2013-06-07T14:19:36Z
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"); } ----
Comment #1 by andrej.mitrovich — 2014-05-02T19:32:48Z
https://github.com/D-Programming-Language/phobos/pull/2141 As was noted it was object.d's clear being called via UFCS.
Comment #2 by yazan.dabain — 2014-10-04T06:01:29Z
This currently correctly fails to compile, and a note has been added to the documentation. Shouldn't this be closed?
Comment #3 by jack — 2016-06-27T20:00:43Z
(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