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
//! **`cstyle-cast`** — a cast written in the C style, `(Widget*)p`, where C++ has four named casts to say which conversion
//! is meant.
//!
//! # Why this reads the tree
//!
//! A C-style cast is a `CastExpr` that **opens with its `(`** and names a type: `(Widget*)p`. The named casts are different
//! shapes (`static_cast<…>(…)` opens with its keyword and carries a template-argument list), and a functional cast (`int(x)`)
//! is a call. So the question is structural, and it cannot produce a finding that is not a cast.
//!
//! Before this, the rule paired `(` with `)` in the file's raw text. That needed three separate defences against things that
//! look like a cast and are not — a preprocessor condition, a parameter list, a template-argument list — and each of those
//! defences was added because the census found the false positive it fixes (813, then 376, then 285 findings on one real
//! project). The tree has none of those shapes: a cast the preprocessor skipped is not in the tree, and a `(` in a parameter
//! list is a `ParameterList` node.
//!
//! # Why the spelling is the last thing computed
//!
//! Measured on a 4000-function file with five casts each: the rule took **35 ms** of a ~600 ms pull, and the two string
//! operations in it were the reason — the type's spelling was built for **every** cast (to test it against `void` and to fill
//! the message), and the opening token was found by trimming each token's text. `CppCastExpr::is_a_c_style_cast` and
//! `CppTypeId::is_void` are the typed questions, and the spelling is built once, after both, only when the finding is reported.
//!
//! The walk is `context.own::<CppCastExpr>()` — **this file's own text** — where `root.syntax().descendants()` also visited the
//! headers inlined into the rendering: a cast in `<string>` is not this file's code to report on.
use CppAstNode;
use ;
/// **`cstyle-cast`** — see the module documentation.
;