From 24da536f4d1cba6c6d450a5ec2122e406751ea13 Mon Sep 17 00:00:00 2001 From: Wyatt Childers Date: Thu, 1 Oct 2026 15:48:07 -0400 Subject: [PATCH] Improve coding style documentation to cover FALLTHROUGH and default_is_unexpected() [] --- doc/source/code_style.rst | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/doc/source/code_style.rst b/doc/source/code_style.rst index 1c48c10998..755265c8c9 100644 --- a/doc/source/code_style.rst +++ b/doc/source/code_style.rst @@ -460,10 +460,17 @@ braces, aligned with the ``if``, and the closing brace aligned with the --------------------- ``switch`` statements should be formatted with their case labels indented -by 2 spaces, the contents further indented by two spaces, and a closing -comment (with two preceding spaces). The opening brace of a scoping block -can be immediately followed on the same line by the first statement of the -block, and its closing brace should have no comment: +by 2 spaces, the contents further indented by two spaces, and the closing +brace annotated with a comment (with two preceding spaces). The opening +brace of a scoping block within a case can be immediately followed on the +same line by the first statement of the block, and its closing brace should +have no comment. If one case intentionally omits the usual closing +``break`` statement and flows into the next, the intent should be +documented by use of the ``FALLTHROUGH`` macro. When the cases of a +``switch`` statement are intended to cover all the enumerators of an +enumeration, the ``default_is_unexpected`` macro should be used to trigger +compiler diagnostics if an enumerator is added and not explicitly handled +by the ``switch``: .. code:: cpp @@ -473,7 +480,7 @@ block, and its closing brace should have no comment: x += y; } - break; + FALLTHROUGH case b: x += 1; break;