www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 19572] New: std.array.Appender.put invokes struct constructor


          Issue ID: 19572
           Summary: std.array.Appender.put invokes struct constructor via
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: default_357-line yahoo.de


struct Struct
    private int key_;

    public int fun() const { return 23; }

    alias fun this;

void main()
    import std.array : Appender;

    Appender!(Struct[]) appender;


    auto result = appender.data[0];

    assert(result.key_ != 23);

What happens is that Appender checks that it can convert const(Struct)
implicitly to Struct, but it does so via cast(Struct), which then invokes
Struct(const(Struct).fun) implicitly.

Appender should cast() its parameter, then rely on implicit conversion to do
the rest.

Jan 10