Skip to content

Commit 0a7802c

Browse files
Improve coding style documentation to cover FALLTHROUGH and default_is_unexpected() []
1 parent 0ac3663 commit 0a7802c

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

‎doc/source/code_style.rst‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -460,10 +460,17 @@ braces, aligned with the ``if``, and the closing brace aligned with the
460460
---------------------
461461

462462
``switch`` statements should be formatted with their case labels indented
463-
by 2 spaces, the contents further indented by two spaces, and a closing
464-
comment (with two preceding spaces). The opening brace of a scoping block
465-
can be immediately followed on the same line by the first statement of the
466-
block, and its closing brace should have no comment:
463+
by 2 spaces, the contents further indented by two spaces, and the closing
464+
brace annotated with a comment (with two preceding spaces). The opening
465+
brace of a scoping block within a case can be immediately followed on the
466+
same line by the first statement of the block, and its closing brace should
467+
have no comment. If one case intentionally omits the usual closing
468+
``break`` statement and flows into the next, the intent should be
469+
documented by use of the ``FALLTHROUGH`` macro. When the cases of a
470+
``switch`` statement are intended to cover all the enumerators of an
471+
enumeration, the ``default_is_unexpected`` macro should be used to trigger
472+
compiler diagnostics if an enumerator is added and not explicitly handled
473+
by the ``switch``:
467474

468475
.. code:: cpp
469476
@@ -473,7 +480,7 @@ block, and its closing brace should have no comment:
473480
474481
x += y;
475482
}
476-
break;
483+
FALLTHROUGH
477484
case b:
478485
x += 1;
479486
break;

0 commit comments

Comments
 (0)