Should the 2.054 feature about warning on implicit fallthrough

Christophe travert at phare.normalesup.org
Thu Sep 15 02:01:47 PDT 2011


bearophile , dans le message (digitalmars.D.learn:29532), a écrit :
> Well, I don't understand the error it gives :-) Are you able to explain it to me?
> 
> 
> import std.stdio;
> void main() {
>      int i = 1;
>      switch(i) {
>          case 0:
>              writeln("case 0");
>              goto default; // needed here
>          aLabel:
>              writeln("a label");
>          default:
>              writeln("default");
>              // But always falls through here
>      }
> }
> 
> test.d(10): Error: switch case fallthrough - use 'goto default;' if intended

If there is a goto aLabel somewhere, the program could go to line 9. 
Then it should fall to the default statement, but the compiler asks for 
an explicit fallthrough, since default is not a simple label, but 
something like a case statement.

-- 
Christophe


More information about the Digitalmars-d-learn mailing list