D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 10291 - formattedWrite() to an Appender fails silently after Appender.clear()
Summary: formattedWrite() to an Appender fails silently after Appender.clear()
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2013-06-07 14:19 UTC by Jared Miller
Modified: 2016-06-27 20:00 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Jared Miller 2013-06-07 14:19:36 UTC
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 Andrej Mitrovic 2014-05-02 19:32:48 UTC
https://github.com/D-Programming-Language/phobos/pull/2141

As was noted it was object.d's clear being called via UFCS.
Comment 2 yazan.dabain 2014-10-04 06:01:29 UTC
This currently correctly fails to compile, and a note has been added to the documentation. Shouldn't this be closed?
Comment 3 Jack Stouffer 2016-06-27 20:00:43 UTC
(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