www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22229] New: Struct initialization via constructor missing

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

--
Aug 20