[Issue 4375] Require explicit braces when 'else' is ambiguous

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Sep 23 09:54:38 PDT 2010


http://d.puremagic.com/issues/show_bug.cgi?id=4375



--- Comment #8 from Jonathan M Davis <jmdavisProg at gmx.com> 2010-09-23 09:53:57 PDT ---
I think what Bearophile wants is that in cases where the grammar (and thus the
compiler) use the typical dangling else rule to determine that the last else
goes with the last if that the compiler should flag it as a warning, on the
theory that the programmer probably screwed up. Apparently there are other
compilers - including gcc - which flag such as a warning. OF course, most
competent programmers would likely have braces around multiple levels of if
anyway, thus totally avoiding the issue, but if the programmer doesn't do that,
then they can end up with the last else going with an if they didn't intend
because they really meant to use braces or perhaps accidentally deleted the if
that went with the else (since there could be several lines between the last if
and the else and the grammar still sees them as part of the same if statement).

Since other compilers such as gcc flag this sort of thing as a warning,
requiring braces to get rid of it, I guess that there's some value in having it
be a warning in dmd. However, since I don't think that it's terribly
responsible to even code in the way that you have to code to get the issue to
show up, I don't think that it's particularly worth having. Still, it wouldn't
hurt anyone who was coding more intelligently, since they'd never see the
warning anyway.

There's enough value to the enhancement that it may get implemented at some
point, but it would be low enough priority that it's probably going to sit in
the queue for a very long time if it ever gets implemented. It's the kind of
thing that you add to a compiler as you're trying to find incremental
improvements to add to a compiler that is essentially already complete (like
gcc).

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list