View mode: basic / threaded / horizontal-split · Log in · Help
February 17, 2013
Switch case falltrhough, regression or intended behavior ?
I have several instance of cases like this :

switch(c) {
	case 'U', 'u' :
	case 'L', 'l' :
		// code . . .
}

dmd from master complains about it (Error: switch case 
fallthrough - use 'goto case;' if intended). It used to work.

Note that in that case, the fix is trivial, but I don't really 
see the point in changing such behavior.
February 17, 2013
Re: Switch case falltrhough, regression or intended behavior ?
On 2/17/13 11:10 AM, deadalnix wrote:
> I have several instance of cases like this :
>
> switch(c) {
> case 'U', 'u' :
> case 'L', 'l' :
> // code . . .
> }
>
> dmd from master complains about it (Error: switch case fallthrough - use
> 'goto case;' if intended). It used to work.
>
> Note that in that case, the fix is trivial, but I don't really see the
> point in changing such behavior.

If there's no intervening code between cases, it should just work.

Andrei
February 17, 2013
Re: Switch case falltrhough, regression or intended behavior ?
On Sun, 17 Feb 2013 11:10:58 -0500, deadalnix <deadalnix@gmail.com> wrote:

> I have several instance of cases like this :
>
> switch(c) {
> 	case 'U', 'u' :
> 	case 'L', 'l' :
> 		// code . . .
> }
>
> dmd from master complains about it (Error: switch case fallthrough - use  
> 'goto case;' if intended). It used to work.
>
> Note that in that case, the fix is trivial, but I don't really see the  
> point in changing such behavior.

looks like a bug.

-Steve
February 17, 2013
Re: Switch case falltrhough, regression or intended behavior ?
On Sunday, 17 February 2013 at 16:10:59 UTC, deadalnix wrote:
> dmd from master complains about it (Error: switch case 
> fallthrough - use 'goto case;' if intended). It used to work.

Does it happen on the staging branch as well?

David
February 17, 2013
Re: Switch case falltrhough, regression or intended behavior ?
On 17/02/2013 16:10, deadalnix wrote:
> I have several instance of cases like this :
>
> switch(c) {
>      case 'U', 'u' :
>      case 'L', 'l' :
>          // code . . .
> }
>
> dmd from master complains about it (Error: switch case fallthrough - use 'goto case;' if
> intended). It used to work.
<snip>

Implicit fall through shouldn't have been allowed from the beginning.  It would appear 
that this has finally been banned.

However, according to the grammar, this is now illegal for a different reason:

http://dlang.org/statement.html#SwitchStatement

CaseStatement:
    case ArgumentList : ScopeStatementList

ScopeStatementList:
    StatementListNoCaseNoDefault

StatementListNoCaseNoDefault:
    StatementNoCaseNoDefault
    StatementNoCaseNoDefault StatementListNoCaseNoDefault

But it does seem odd to people coming from C(++), since it doesn't seem aimed at either 
simplifying the grammar or shielding the programmer's foot against self-inflicted gunfire.

But it does address this issue, which I actually hadn't taken in had been resolved
http://d.puremagic.com/issues/show_bug.cgi?id=603

If we want to still allow the old C syntax for multiple cases, then we can define

CaseStatement:
    case ArgumentList : ScopeStatementList
    case ArgumentList : CaseStatement

which is only a small change....

Stewart.
February 17, 2013
Re: Switch case falltrhough, regression or intended behavior ?
On Sunday, 17 February 2013 at 17:16:44 UTC, David Nadlinger 
wrote:
> On Sunday, 17 February 2013 at 16:10:59 UTC, deadalnix wrote:
>> dmd from master complains about it (Error: switch case 
>> fallthrough - use 'goto case;' if intended). It used to work.
>
> Does it happen on the staging branch as well?
>
> David

I don't know and I can't test as I'm running a huge dustmite 
right now (likely to run all night long).
February 17, 2013
Re: Switch case falltrhough, regression or intended behavior ?
On Sunday, February 17, 2013 17:26:01 Stewart Gordon wrote:
> On 17/02/2013 16:10, deadalnix wrote:
> > I have several instance of cases like this :
> > 
> > switch(c) {
> > 
> >      case 'U', 'u' :
> >      
> >      case 'L', 'l' :
> >          // code . . .
> > 
> > }
> > 
> > dmd from master complains about it (Error: switch case fallthrough - use
> > 'goto case;' if intended). It used to work.
> 
> <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. If the compiler is 
warning about falling through an empty case statement, it's a bug.

- Jonathan M Davis
February 17, 2013
Re: Switch case falltrhough, regression or intended behavior ?
On 2/17/13, deadalnix <deadalnix@gmail.com> wrote:
> It used to work.

Are you sure it's a regression?

2.062:
$ dmd test.d
>

$ dmd -w test.d
> test.d(8): Error: switch case fallthrough - use 'goto case;' if intended
> test.d(10): Error: switch case fallthrough - use 'goto default;' if intended

I've tested from 2.062 to 2.057 and they all have this behavior.
February 17, 2013
Re: Switch case falltrhough, regression or intended behavior ?
On Sun, 17 Feb 2013 22:03:33 +0100
Andrej Mitrovic <andrej.mitrovich@gmail.com> wrote:

> On 2/17/13, deadalnix <deadalnix@gmail.com> wrote:
> > It used to work.
> 
> Are you sure it's a regression?
> 
> 2.062:
> $ dmd test.d
> >
> 
> $ dmd -w test.d
> > test.d(8): Error: switch case fallthrough - use 'goto case;' if
> > intended test.d(10): Error: switch case fallthrough - use 'goto
> > default;' if intended
> 
> I've tested from 2.062 to 2.057 and they all have this behavior.

Hmm, that brings up a different (though minor) issue: If it's a
warning, why does it say "Error"?
February 17, 2013
Re: Switch case falltrhough, regression or intended behavior ?
On 2/17/13, Nick Sabalausky <SeeWebsiteToContactMe@semitwist.com> wrote:
> Hmm, that brings up a different (though minor) issue: If it's a
> warning, why does it say "Error"?

I can see in the source there's a check for the -w flag but then an
error is raised by mistake. This should either be an error regardless
of -w or be changed into a warning.
« First   ‹ Prev
1 2 3
Top | Discussion index | About this forum | D home