You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: "Reference for Microsoft C++ Code Analysis warning C26819 in Visual Studio."
4
+
ms.date: 04/22/2020
5
+
ms.topic: "reference"
6
+
f1_keywords: ["C26819"]
7
+
helpviewer_keywords: ["C26819"]
8
+
---
9
+
# C26819
10
+
11
+
> Unannotated fallthrough between switch labels (es.78).
12
+
13
+
## Remarks
14
+
15
+
This check covers implicit fallthrough in switch statements. Implicit fallthrough is when control flow transfers from one switch case directly into a following switch case without the use of the `[[fallthrough]];` statement. This warning is raised when an implicit fallthrough is detected in a switch case containing at least one statement.
16
+
17
+
For more information, see [ES.78: Don't rely on implicit fallthrough in `switch` statements](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Res-break) in the C++ Core Guidelines.
18
+
19
+
## Example
20
+
21
+
In this sample, implicit fallthrough occurs from a non-empty switch case into a following case.
22
+
23
+
```cpp
24
+
voidfn1();
25
+
voidfn2();
26
+
27
+
voidfoo(int a)
28
+
{
29
+
switch (a)
30
+
{
31
+
case 0: // implicit fallthrough from case 0 to case 1 is OK because case 0 is empty
32
+
case 1:
33
+
fn1(); // implicit fallthrough from case 1 into case 2
34
+
case 2:
35
+
fn2();
36
+
break;
37
+
default:
38
+
break;
39
+
}
40
+
}
41
+
```
42
+
43
+
## Solution
44
+
45
+
To fix this issue, insert a `[[fallthrough]];` statement where the fallthrough occurs.
46
+
47
+
```cpp
48
+
void fn1();
49
+
void fn2();
50
+
51
+
void foo(int a)
52
+
{
53
+
switch (a)
54
+
{
55
+
case 0:
56
+
case 1:
57
+
fn1();
58
+
[[fallthrough]]; // fallthrough is explicit
59
+
case 2:
60
+
fn2();
61
+
break;
62
+
default:
63
+
break;
64
+
}
65
+
}
66
+
```
67
+
68
+
Another way to fix the issue is to remove the implicit fallthrough.
69
+
70
+
```cpp
71
+
voidfn1();
72
+
voidfn2();
73
+
74
+
voidfoo(int a)
75
+
{
76
+
switch (a)
77
+
{
78
+
case 0:
79
+
case 1:
80
+
fn1();
81
+
break; // case 1 no longer falls through into case 2
0 commit comments