The forgotten deprecation: switch case fall-through
kdevel
kdevel at vogtner.de
Sun Dec 13 20:45:55 UTC 2020
On Thursday, 3 December 2020 at 09:29:12 UTC, Bastiaan Veelo
wrote:
> Switch case fallthrough (non-empty cases that do not end with a
> break, continue, goto, return, throw or assert(0) statement)
> has been deprecated for more than 9 years [1]. As I am fixing a
> bug due to unintended case fall-through today, I am wondering
> when its deprecation period will be ended.
For the non-trivial ArgumentList case [1] it has not even startet
yet
~~~switchbreak.d
int foo (string s)
{
int a;
switch (s) {
case "eins", "zwei":
a = 1;
default: // no warning
}
return a;
}
int bar (string s)
{
int a;
switch (s) {
case "eins": case "zwei":
a = 2;
default: // deprecation warning
}
return a;
}
unittest {
assert (foo ("") == 0);
assert (foo ("eins") == 1);
assert (foo ("zwei") == 1);
assert (bar ("") == 0);
assert (bar ("eins") == 2);
assert (bar ("zwei") == 2);
}
~~~
$ dmd -unittest -main -run switchbreak
switchbreak.d(18): Deprecation: switch case fallthrough - use
'goto default;' if intended
1 unittests passed
[1] https://dlang.org/spec/statement.html#switch-statement
More information about the Digitalmars-d
mailing list