On 17/02/2013 20:07, Jonathan M Davis wrote:
<snip>
Implicit fall through shouldn't have been allowed from the beginning.  It
would appear that this has finally been banned.

Implicit fallthrough is a warning when a case stament is non-empty, but if
it's empty (as in the example), then there is no warning.

What version of DMD are you using?

I'm getting stranger than this (2.061):

----- switch_fallthrough_a.d -----
void main() {
    char c = 'x';
    switch(c) {
        case 'U', 'u' :
        case 'L', 'l' :
            // code . . .
        default:
    }
}
----- switch_fallthrough_b.d -----
void main() {
    char c = 'x';
    switch(c) {
        case 'U', 'u' :
            c = 'q';
        case 'L', 'l' :
            c = 'r';
            // code . . .
        default:
    }
}
----------
C:\Users\Stewart\Documents\Programming\D\Tests>dmd switch_fallthrough_a.d

C:\Users\Stewart\Documents\Programming\D\Tests>dmd -w switch_fallthrough_a.d
switch_fallthrough_a.d(5): Error: switch case fallthrough - use 'goto case;' if 
intended
switch_fallthrough_a.d(7): Error: switch case fallthrough - use 'goto default;' 
if intended

C:\Users\Stewart\Documents\Programming\D\Tests>dmd switch_fallthrough_b.d

C:\Users\Stewart\Documents\Programming\D\Tests>dmd -w switch_fallthrough_b.d
switch_fallthrough_b.d(6): Error: switch case fallthrough - use 'goto case;' if 
intended
switch_fallthrough_b.d(9): Error: switch case fallthrough - use 'goto default;' 
if intended
----------

You see, it's independent of whether there are any statements between the two case markers, and there's a further anomaly in that it's an _error_ that's emitted only if _warnings_ are enabled.

If the compiler is warning about falling through an empty case statement, it's 
a bug.

There's no such thing as an "empty case statement", unless you mean the case where the ScopeStatementList is ";" or "{}" by itself. Look at the grammar carefully.

So by the current spec, the first example is a syntax error, since a CaseStatement explicitly forbids another CaseStatement as its body.

Stewart.

Reply via email to