1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//! **`unnecessary-branch`**: a branch the program cannot take, or a condition that is already decided.
//!
//! ```cpp
//! if (true) { work(); } // the `if` decides nothing
//! if (false) { work(); } // and this body is never run
//! ```
//!
//! # What is reported, and what is emphatically not
//!
//! Only a condition that is **a literal written where the condition goes** — `true`, `false`, `0`, `1`. Nothing is
//! evaluated:
//!
//! ```text
//! reported if (true) … if (false) … if ((0)) …
//! not reported if (MY_FLAG) a macro: its value is the preprocessor's, and this reads the tree
//! not reported if (DEBUG) a name: folding it is another layer's question
//! not reported if (1 == 1) arithmetic on literals — a constant folder, which this is not
//! not reported if (sizeof(T) > 4) ditto
//! not reported #if 0 … #endif the preprocessor removes it before the parse
//! ```
//!
//! The line between the two lists is the whole design of the check: **a literal is a fact about the text, and
//! everything else is a question**. Constant folding is a feature with a semantics of its own — integer promotion,
//! `constexpr` functions, macros — and a check that did half of it would be wrong in the half it did.
//!
//! # Read as text, deliberately
//!
//! The condition is taken from the statement's **own text**, between the first `(` and its match, rather than from
//! the tree's shape. A condition is where the grammar's recovery is most visible — `if (x` with the paren missing
//! produces a node that holds the rest of the file — and a check asking about literals has no business reading a
//! recovered tree. The text is what the reader wrote.
//!
//! # Why the dead branch is reported rather than the live one
//!
//! A finding is a claim about a place. `if (false) { … }` is a claim about the **whole statement** — nothing in it
//! runs — while `if (true) { … }` is a claim about the **condition**, which is a decision already made. The two
//! messages say which one the reader is looking at.
use CppAstNode;
use ;
/// **`unnecessary-branch`** — see the module documentation.
;