Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
March 03, 2015 Implicit fall through not detected (Example from lex.html) | ||||
---|---|---|---|---|
| ||||
Hi, I am little bit confused. I am copied the switch example from lex.html and expected that case 6 will lead to a syntax error due to the missing break statement. But the example compiles without error (C:>dmd app) I tried 3 different dmd version, also the newest beta. Kind regards André import std.stdio: writeln; void main() { int number; string message; switch (number) { default: // valid throw new Exception("unknown number"); case 3: // valid message ~= "three "; break; case 5: // valid message ~= "five "; goto case; case 6: // ERROR: implicit fall-through message ~= "six "; case 1: // valid case 2: // valid message = "one or two"; } } |
March 03, 2015 Re: Implicit fall through not detected (Example from lex.html) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andre | On 03/02/2015 10:58 PM, Andre wrote:
> Hi,
>
> I am little bit confused. I am copied the switch example from lex.html
> and expected that case 6 will lead to a syntax error due to the missing
> break statement. But the example compiles without error (C:>dmd app)
>
> I tried 3 different dmd version, also the newest beta.
>
> Kind regards
> André
>
> import std.stdio: writeln;
>
> void main()
> {
>
> int number;
> string message;
>
> switch (number)
> {
> default: // valid
> throw new Exception("unknown number");
>
> case 3: // valid
> message ~= "three ";
> break;
>
> case 5: // valid
> message ~= "five ";
> goto case;
>
> case 6: // ERROR: implicit fall-through
> message ~= "six ";
>
> case 1: // valid
> case 2: // valid
> message = "one or two";
> }
>
> }
Compile with -w command line switch. :)
Ali
|
March 03, 2015 Re: Implicit fall through not detected (Example from lex.html) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andre Attachments: | On Tue, 03 Mar 2015 06:58:14 +0000, Andre wrote:
> Hi,
>
> I am little bit confused. I am copied the switch example from lex.html and expected that case 6 will lead to a syntax error due to the missing break statement. But the example compiles without error (C:>dmd app)
implicit fallthru is not a fatal bug (but i believe it should be), it generates only warning.
|
March 03, 2015 Re: Implicit fall through not detected (Example from lex.html) | ||||
---|---|---|---|---|
| ||||
Posted in reply to ketmar | On Tuesday, 3 March 2015 at 07:27:33 UTC, ketmar wrote:
>
> implicit fallthru is not a fatal bug (but i believe it should be), it
> generates only warning.
I am also not really happy with the actual behavor (w / wi switch needed) because the documentation is clear about that it is an error:
-- from language reference:
A ScopeStatementList must either be empty, or be ended with a ContinueStatement, BreakStatement, ReturnStatement, GotoStatement, ThrowStatement or assert(0) expression unless this is the last case. This is to set apart with C's error-prone implicit fall-through behavior. goto case; could be used for explicit fall-through
--
Fortunately dub is using the correct switches by default
Kind regards
André
|
March 03, 2015 Re: Implicit fall through not detected (Example from lex.html) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andre | Andre:
> I am also not really happy with the actual behavor (w / wi switch needed)
You shall always compile your D code with warnings active, unless you need them disabled for some real reason.
Eventually the fall through warning will become a deprecation and then an error. It's meant to be an error, but in D we introduce errors slowly.
Bye,
bearophile
|
Copyright © 1999-2021 by the D Language Foundation