On Wed, Sep 2, 2009 at 8:43 PM, Ryan Leavengood<[email protected]> wrote: > On Wed, Sep 2, 2009 at 11:15 PM, TAMURA, Kent<[email protected]> wrote: >> >> A few days ago, this rule brought a real bug to me. >> Existing code: >> if (attr->name() == fooAttr) >> doSometing(); >> else if (attr->name() == barAttr) ... >> I added "if" like: >> if (attr->name() == fooAttr) >> if (isBaz()) >> doSometing(); >> else if (attr->name() == barAttr) ... >> The "else" clause unexpectedly attached to "if (isBaz())" >> I wasted about an hour to found this bug. > > Yes that's annoying, but the moment you added that second if the first > if was no longer a single statement. >
I suppose it depends on your definitions, but the compiler would consider those both single statements. That's the whole reason why the dangling else is evil. -- Dirk (Among the many WebKit rules that surprised me, I think this one surprised me the most, but I'm not arguing that it should be changed at this point). _______________________________________________ webkit-dev mailing list [email protected] http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev

