fallthrough explanation and example are fixed. (#115)

* fallthrough explanation and example are fixed.

* Sentence typo fixed and written more concisely.
This commit is contained in:
clepz
2022-11-01 19:53:49 +03:00
committed by GitHub
parent bd4cb84e80
commit 40b3823256
2 changed files with 16 additions and 4 deletions

View File

@@ -266,14 +266,20 @@ byte e = byte{256}; // ERROR
### fallthrough, nodiscard, maybe_unused attributes ### fallthrough, nodiscard, maybe_unused attributes
C++17 introduces three new attributes: `[[fallthrough]]`, `[[nodiscard]]` and `[[maybe_unused]]`. 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++ ```c++
switch (n) { switch (n) {
case 1: [[fallthrough]] case 1:
// ... // ...
[[fallthrough]];
case 2: case 2:
// ... // ...
break; break;
case 3:
// ...
[[fallthrough]];
default:
// ...
} }
``` ```

View File

@@ -917,14 +917,20 @@ byte e = byte{256}; // ERROR
### fallthrough, nodiscard, maybe_unused attributes ### fallthrough, nodiscard, maybe_unused attributes
C++17 introduces three new attributes: `[[fallthrough]]`, `[[nodiscard]]` and `[[maybe_unused]]`. 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++ ```c++
switch (n) { switch (n) {
case 1: [[fallthrough]] case 1:
// ... // ...
[[fallthrough]];
case 2: case 2:
// ... // ...
break; break;
case 3:
// ...
[[fallthrough]];
default:
// ...
} }
``` ```