From 40b3823256e4070c10b258099424aecfc397a0c3 Mon Sep 17 00:00:00 2001 From: clepz Date: Tue, 1 Nov 2022 19:53:49 +0300 Subject: [PATCH] fallthrough explanation and example are fixed. (#115) * fallthrough explanation and example are fixed. * Sentence typo fixed and written more concisely. --- CPP17.md | 10 ++++++++-- README.md | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/CPP17.md b/CPP17.md index 9898ac9..51e4683 100644 --- a/CPP17.md +++ b/CPP17.md @@ -266,14 +266,20 @@ byte e = byte{256}; // ERROR ### fallthrough, nodiscard, maybe_unused attributes C++17 introduces three new attributes: `[[fallthrough]]`, `[[nodiscard]]` and `[[maybe_unused]]`. -* `[[fallthrough]]` indicates to the compiler that falling through in a switch statement is intended behavior. +* `[[fallthrough]]` indicates to the compiler that falling through in a switch statement is intended behavior. This attribute may only be used in a switch statement, and must be placed before the next case/default label. ```c++ switch (n) { - case 1: [[fallthrough]] + case 1: // ... + [[fallthrough]]; case 2: // ... break; + case 3: + // ... + [[fallthrough]]; + default: + // ... } ``` diff --git a/README.md b/README.md index 047be8d..980446d 100644 --- a/README.md +++ b/README.md @@ -917,14 +917,20 @@ byte e = byte{256}; // ERROR ### fallthrough, nodiscard, maybe_unused attributes C++17 introduces three new attributes: `[[fallthrough]]`, `[[nodiscard]]` and `[[maybe_unused]]`. -* `[[fallthrough]]` indicates to the compiler that falling through in a switch statement is intended behavior. +* `[[fallthrough]]` indicates to the compiler that falling through in a switch statement is intended behavior. This attribute may only be used in a switch statement, and must be placed before the next case/default label. ```c++ switch (n) { - case 1: [[fallthrough]] + case 1: // ... + [[fallthrough]]; case 2: // ... break; + case 3: + // ... + [[fallthrough]]; + default: + // ... } ```