Skip to content

Commit 40b3823

Browse files
authored
fallthrough explanation and example are fixed. (AnthonyCalandra#115)
* fallthrough explanation and example are fixed. * Sentence typo fixed and written more concisely.
1 parent bd4cb84 commit 40b3823

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

CPP17.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,14 +266,20 @@ byte e = byte{256}; // ERROR
266266
267267
### fallthrough, nodiscard, maybe_unused attributes
268268
C++17 introduces three new attributes: `[[fallthrough]]`, `[[nodiscard]]` and `[[maybe_unused]]`.
269-
* `[[fallthrough]]` indicates to the compiler that falling through in a switch statement is intended behavior.
269+
* `[[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.
270270
```c++
271271
switch (n) {
272-
case 1: [[fallthrough]]
272+
case 1:
273273
// ...
274+
[[fallthrough]];
274275
case 2:
275276
// ...
276277
break;
278+
case 3:
279+
// ...
280+
[[fallthrough]];
281+
default:
282+
// ...
277283
}
278284
```
279285

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -917,14 +917,20 @@ byte e = byte{256}; // ERROR
917917
918918
### fallthrough, nodiscard, maybe_unused attributes
919919
C++17 introduces three new attributes: `[[fallthrough]]`, `[[nodiscard]]` and `[[maybe_unused]]`.
920-
* `[[fallthrough]]` indicates to the compiler that falling through in a switch statement is intended behavior.
920+
* `[[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.
921921
```c++
922922
switch (n) {
923-
case 1: [[fallthrough]]
923+
case 1:
924924
// ...
925+
[[fallthrough]];
925926
case 2:
926927
// ...
927928
break;
929+
case 3:
930+
// ...
931+
[[fallthrough]];
932+
default:
933+
// ...
928934
}
929935
```
930936

0 commit comments

Comments
 (0)