[Issue 15924] formattedWrite doesn't write to empty appender

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Fri Apr 15 10:02:17 PDT 2016


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

ag0aep6g at gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ag0aep6g at gmail.com
           Hardware|x86_64                      |All
                 OS|Linux                       |All

--- Comment #1 from ag0aep6g at gmail.com ---
The issue is, of course, that a default initialized Appender does not have an
associated array yet. When such a not-really-initialized Appender is copied,
the copy and the original are completely independent from each other. Writing
to one doesn't affect the other. In the formattedWrite call, buffer is being
copied, so formattedWrite writes to a location of which buffer doesn't know.

Other variants that work:
----
auto buffer = appender!string;
formattedWrite(buffer, "foo");

Appender!string buffer;
formattedWrite(&buffer, "foo");
----

As for a fix, I'm not sure what should be done here. `disable this();` for
Appender is an idea, but that would probably break quite some code.

--


More information about the Digitalmars-d-bugs mailing list