[vtk-developers] coding standards & switch case label accidental fallthrough
Sean McBride
sean at rogue-research.com
Tue Apr 7 12:36:18 EDT 2015
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
More information about the vtk-developers
mailing list