[Issue 19885] New: possibility to skip required initialization in constructor using ref parameter
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat May 18 17:57:35 UTC 2019
https://issues.dlang.org/show_bug.cgi?id=19885
Issue ID: 19885
Summary: possibility to skip required initialization in
constructor using ref parameter
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: regression
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: regnellday at protonmail.com
This code compiles (since 2.081.2), but shouldn't:
struct A
{
@disable this();
this(int) {}
}
struct B
{
A a;
this(int)
{
f(a);
}
}
void f(ref A a) {}
void main()
{
B b = B(1);
}
The `a` must be constructed in the `B` constructor. But if we pass it somewhere
via ref parameter, compiler ignores `a` and leaves it in default state.
By the way, if we change ref to out, then there is normal `Error: cannot have
out parameter of type A because the default construction is disabled`.
--
More information about the Digitalmars-d-bugs
mailing list