digitalmars.D.learn - Implicit fall through not detected (Example from lex.html)
- Andre (32/32) Mar 02 2015 Hi,
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (3/32) Mar 02 2015 Compile with -w command line switch. :)
- ketmar (3/8) Mar 02 2015 implicit fallthru is not a fatal bug (but i believe it should be), it=20
- Andre (15/18) Mar 03 2015 I am also not really happy with the actual behavor (w / wi switch
- bearophile (8/10) Mar 03 2015 You shall always compile your D code with warnings active, unless
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";
}
}
Mar 02 2015
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
Mar 02 2015
On Tue, 03 Mar 2015 06:58:14 +0000, Andre wrote:Hi, =20 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=20 generates only warning.=
Mar 02 2015
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é
Mar 03 2015
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
Mar 03 2015









=?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> 