Bug 17331 – appender can't be used for initialization twice

Status
NEW
Severity
normal
Priority
P3
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2017-04-19T01:59:40Z
Last change time
2024-12-01T16:30:08Z
Assigned to
No Owner
Creator
Heromyth
Moved to GitHub: phobos#10248 →

Comments

Comment #0 by bitworld — 2017-04-19T01:59:40Z
Compiler: DMD32 D Compiler v2.074.0 OS: Windows, Ubuntu Here is my test code. import std.stdio; import std.array; struct PackageHandler { private auto buffer = appender!(ubyte[])(); // The bug is here // private Appender!(ubyte[]) buffer; // It's ok. void test() { assert(buffer.data.length == 0); // for test } void append(ubyte[] data) { buffer ~= data; } void reset() { buffer.clear(); } } class AppenderTester { private PackageHandler handler; this() { handler.test(); } void append() { handler.append([11, 12, 13]); } void clear() { handler.reset(); } } void main() { AppenderTester tester01 = new AppenderTester(); tester01.append(); // tester01.clear(); AppenderTester tester02 = new AppenderTester(); }
Comment #1 by chalucha — 2018-03-20T17:15:56Z
Here is another one: import std.stdio; import std.array; class Foo { auto bar = appender!(int[])(); //auto bar = Appender!(int[])(); // Works ok } void main() { auto f1 = new Foo(); auto f2 = new Foo(); f1.bar ~= 1; f2.bar ~= 2; writeln(f1.bar.data); writeln(f2.bar.data); } With appender output is: [1, 2] [1, 2] With Appender: [1] [2] Tested on v2.078.3 and v2.079.0
Comment #2 by chalucha — 2018-03-20T17:21:18Z
My guess is that problem is here: https://github.com/dlang/phobos/blob/master/std/array.d#L2884 As this constructor is called when appender is used with null arr parameter. So I guess that in CTFE _data is set to the same struct pointer?
Comment #3 by robert.schadek — 2024-12-01T16:30:08Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/10248 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB