Switch case falltrhough, regression or intended behavior ?

Stewart Gordon smjg_1998 at yahoo.com
Sun Feb 17 18:01:55 PST 2013


On 18/02/2013 01:30, Jonathan M Davis wrote:
> On Monday, February 18, 2013 01:04:41 Stewart Gordon wrote:
>> On 17/02/2013 20:07, Jonathan M Davis wrote:
>> <snip>
<snip>
>>> 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?
>
> That's irrelevant. I'm stating what the intended behavior is. If the compiler
> doesn't follow that behavior, then it's a bug.

So you meant to say "there is meant to be no warning".

<snip>
>> and there's a further anomaly in that it's an _error_
>> that's emitted only if _warnings_ are enabled.
>
> That's normal. That's what -w does. If you don't use any compiler flags, then
> you get no warnings. If you use -w, you get them, but they're treated as
> errors.

No, treatment as errors has nothing to do with the wording of compiler messages.  It's 
completely independent of this.  As I explained at 01:21 UTC.

> If you use -wi, then you get "informational warnings" which is what
> most everyone expects compilers to do normally - i.e. print the warning but
> not treat it as an error - but Walter Bright thinks differently about such
> things than many people, and his compilers often don't do what many people
> would consider normal. He doesn't believe in warnings in the first place.
> Rather, he thinks that everything should be an error or not as far as the
> compiler is concerned (which I very much agree with), but unfortunately, he
> gave in enough to create the -w flag (and eventually, the -wi flag), and when he
> did, he didn't follow the behavior of your average compiler, which has
> generated a fair bit of confusion with regards to warnings.
<snip>

Yes, Walter claimed early on that anything that compilers tend to emit warnings for ought 
to be forbidden by the language.  However, he hasn't followed this principle, and so we 
were left with the awkward situation whereby certain kinds of obviously buggy (or at least 
suspect) code are just silently accepted.

The "no warnings" philosophy we had for a while was also a detriment to one of D's other 
design goals, to have different compiler vendors competing on quality of implementation.

Still, for as long as the language spec is still under development, one might as well make 
suspicious code illegal rather than putting warnings in the reference implementation 
(unless there really is a point of contention in what should be legal).  But third party 
implementers don't have this recourse, so that's why warnings are useful.  Part of what 
makes a quality implementation is what warnings it generates.

Stewart.


More information about the Digitalmars-d mailing list