clang -Wimplicit-fallthrough and missing breaks

Caolán McNamara caolanm at redhat.com
Mon May 9 08:54:42 UTC 2016


Does the clang version we use for all the spiffy warnings support 
-Wimplicit-fallthrough ?

I see firefox has a MOZ_FALLTHROUGH macro that expands
to [[clang::fallthrough]] for clang and just plain /*fall-through*/ for
everything else.

If we had support for something like that, and could rewrite all our
current /*fall-through*/ and //FALL_THROUGH etc comments to that macro,
then perhaps we could enable this warning by default and we wouldn't
see as many of these missing breaks getting missed until the next
coverity run as I've been seeing over the last few weeks.

On that topic, while I don't want to start a style war, some
consistency in switch/case/break+brace layout would, I suspect, be
helpful. I'm a fan of an indent after switch and after case, and break
aligned to the body of case. With any scoping braces required for a
case encompassing the final break

switch (foo)
{
    case bar:
        things...
        break;
    case baz:
    {
        things...
        break;
    }
}

(which is the same as the mozilla guidelines https://developer.mozilla.
org/en-US/docs/Mozilla/Developer_guide/Coding_Style)


this is the other sane pattern we generally use, which I could live
with. Though I think we should use one or the other consistently.

switch (foo)
{
    case bar:
        things...
    break;
    case baz:
    {
        things...
    }
    break;
}

While this I find particularly painful and common when switch
statements end up multipage long with switches inside switches

switch (foo)
{
    case bar:
    break;
    case baz:
        {
            things...
        }
        break;
    case qux:
        things...
        break;
    case tay:
        {
            things...
        }
    break;
}


More information about the LibreOffice mailing list