[vtk-developers] coding standards & switch case label accidental fallthrough

David Cole DLRdave at aol.com
Tue Apr 7 13:42:51 EDT 2015


Is there really no way to refactor and simply eliminate all the
"intentional" fall throughs? It's a really nasty style to be allowing.
It should be discouraged in general.

Just my opinion, of course.

D


On Tue, Apr 7, 2015 at 12:36 PM, Sean McBride <sean at rogue-research.com> wrote:
> Hi all,
>
> I'd like to propose a coding standards change...
>
> I have a patch here:
> <https://gitlab.kitware.com/vtk/vtk/merge_requests/59>
>
> that fixes clang -Wimplicit-fallthrough warnings, which warn when you have adjacent case labels in a switch without breaks between them.  In other words, warns when you forget a 'break', which is pretty common, and often not deliberate.
>
> For deliberate fall-though, it provides a clang-only C++11 attribute to suppress the warning, which I wrapped into a macro VTK_FALLTHROUGH.
>
> So I propose that, by agreed convention, all deliberate switch case fall-through must use VTK_FALLTHOUGH annotations, ex:
>
>  switch(var)
>    {
>    case 1:
>      bar();
>      break;
>
>    case 2:
>      baz();
>      VTK_FALLTHROUGH;
>
>    case 3:
>      foo();
>      break;
>    }
>
> Failure to use VTK_FALLTHROUGH above will cause warnings on C++11 clang builds.  On other compilers it's less helpful, but still nicely self-documenting.
>
> Cheers,
>
> --
> ____________________________________________________________
> Sean McBride, B. Eng                 sean at rogue-research.com
> Rogue Research                        www.rogue-research.com
> Mac Software Developer              Montréal, Québec, Canada
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Search the list archives at: http://markmail.org/search/?q=vtk-developers
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtk-developers
>


More information about the vtk-developers mailing list