January 10, 2019 [Issue 19572] New: std.array.Appender.put invokes struct constructor via cast | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=19572 Issue ID: 19572 Summary: std.array.Appender.put invokes struct constructor via cast 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 Repro: struct Struct { private int key_; public int fun() const { return 23; } alias fun this; } void main() { import std.array : Appender; Appender!(Struct[]) appender; appender.put(const(Struct)(42)); 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. -- |
Copyright © 1999-2021 by the D Language Foundation