[webkit-dev] Proposal for coding guidelines: Do not use fall-through switch cases inside #ifdef's

Bruno Abinader brunoabinader at gmail.com
Fri Aug 17 09:32:19 PDT 2012


I found a very interesting issue on some platform builds that I would
like to share. See the example below:

...
    case CSSPropertyTextDecoration:
#if ENABLE(CSS3_TEXT_DECORATION)
    case CSSPropertyWebkitTextDecorationLine:
#endif // CSS3_TEXT_DECORATION
        return renderTextDecorationFlagsToCSSValue(style->textDecoration());
...

This breaks build on gtk, win and mac platforms as the precompiler is
unable to understand it as a fall-through case, AFAIK. Proper
implementation would be, then:

...
    case CSSPropertyTextDecoration:
        return renderTextDecorationFlagsToCSSValue(style->textDecoration());
#if ENABLE(CSS3_TEXT_DECORATION)
    case CSSPropertyWebkitTextDecorationLine:
        return renderTextDecorationFlagsToCSSValue(style->textDecoration());
#endif // CSS3_TEXT_DECORATION
...

Where each switch case is handled individually (if you're curious
about it, it is fixed in bug 90493). Said this, I would like to
propose it as a code guideline. As always, inputs and comments are
welcome!

Best regards,

-- 
Bruno de Oliveira Abinader


More information about the webkit-dev mailing list