[Issue 22229] New: Struct initialization via constructor missing from language spec
    d-bugmail at puremagic.com 
    d-bugmail at puremagic.com
       
    Fri Aug 20 19:11:57 UTC 2021
    
    
  
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 at puremagic.com
          Reporter: snarwin+bugzilla at 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
--
    
    
More information about the Digitalmars-d-bugs
mailing list