[Issue 22719] New: Fallthrough detection falls through.
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Jan 31 13:54:35 UTC 2022
https://issues.dlang.org/show_bug.cgi?id=22719
Issue ID: 22719
Summary: Fallthrough detection falls through.
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: major
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: deadalnix at gmail.com
Sample code:
import std.stdio;
void foo() {
writeln(__FUNCTION__);
}
void bar() {
writeln(__FUNCTION__);
}
void fun(int i) {
int n = 3;
switch (i) {
while (n --> 0)
case 0:
case 1:
foo();
bar();
default:
writeln("default");
}
}
void main() {
fun(1);
}
The fun function ought to be parsed as:
void fun(int i) {
int n = 3;
switch (i) {
while (n --> 0) {
case 0:
case 1:
foo();
bar();
}
default:
writeln("default");
}
}
The control flow falls through into the default case without a goto default.
This is supposed to be an error in D, but DMD accepts it in this case.
--
More information about the Digitalmars-d-bugs
mailing list