[Issue 21547] New: Oder of constructor declaration affects struct initializer
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Jan 14 09:16:53 UTC 2021
https://issues.dlang.org/show_bug.cgi?id=21547
Issue ID: 21547
Summary: Oder of constructor declaration affects struct
initializer
Product: D
Version: D2
Hardware: x86_64
OS: All
Status: NEW
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: razvan.nitu1305 at gmail.com
struct Bar
{
@disable this(int a) {}
this(int a, int b) {}
string a;
uint b;
}
void main ()
{
Bar b = { a: "Hello", b: 42 };
}
Compiles fine. Whereas:
struct Bar
{
this(int a, int b) {}
@disable this(int a) {}
string a;
uint b;
}
void main ()
{
Bar b = { a: "Hello", b: 42 };
}
Gives: test.d(12): Error: struct `Bar` has constructors, cannot use `{
initializers }`, use `Bar( initializers )` instead
Expected result: both examples give the same error.
The problem is that the compiler checks the first declared constructor and if
it is disabled it considers that the struct does not have any other
constructors. It should check the entire overload set.
--
More information about the Digitalmars-d-bugs
mailing list