August 20, 2021 [Issue 22229] New: Struct initialization via constructor missing from language spec | ||||
|---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=22229 Issue ID: 22229 Summary: Struct initialization via constructor missing from language spec Product: D Version: D2 Hardware: All OS: All Status: NEW Severity: normal Priority: P1 Component: dlang.org Assignee: nobody@puremagic.com Reporter: snarwin+bugzilla@gmail.com A struct can be initialized with a value of a different type if it has a constructor that accepts a value of that type: --- struct S { this(int n) {} } S s = 123; // ok: calls constructor --- However, neither the language spec section on dynamic initialization of structs [1] nor the section on struct constructors [2] mention that constructors can be called with this syntax. [1] https://dlang.org/spec/struct.html#dynamic_struct_init [2] https://dlang.org/spec/struct.html#struct-constructor -- | ||||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply