[Issue 18688] New: Constructors shouldn't have implicit super call if it throws
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Mar 28 14:43:59 UTC 2018
https://issues.dlang.org/show_bug.cgi?id=18688
Issue ID: 18688
Summary: Constructors shouldn't have implicit super call if it
throws
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: enhancement
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: yshuiv7 at gmail.com
This example doesn't compile:
class A {
this(int x){}
@disable this();
}
class B: A {
this(int x) {
super(x);
}
this(string b) {
switch(b) {
case "a":break;
default: assert(false);
}
this(1);
}
}
Possibly because the compile decides 'this(1)' is not always reachable, and
tries to implicitly call super() in that case. But if 'this(1)' is not
reachable, the constructor is guaranteed to throw, thus super call should not
be required.
Also, this program has almost the same behavior (SwitchError is thrown instead
of AssertError), but it compiles:
class A {
this(int x){}
@disable this();
}
class B: A {
this(int x) {
super(x);
}
this(string b) {
final switch(b) {
case "a":break;
}
this(1);
}
}
--
More information about the Digitalmars-d-bugs
mailing list