mirror of
https://github.com/AnthonyCalandra/modern-cpp-features.git
synced 2025-12-17 10:04:35 +03:00
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:
10
CPP17.md
10
CPP17.md
@@ -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:
|
||||||
|
// ...
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
10
README.md
10
README.md
@@ -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:
|
||||||
|
// ...
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user