Commit c45b003
committed
Fix RULE-7-0-1 false positives for bool-to-reference bindings
`NoConversionFromBool.ql` excludes conversions whose destination type,
after `stripTopLevelSpecifiers()`, is `bool`. `ReferenceType` does not
override `stripTopLevelSpecifiers()`, so a `bool` value bound to a
`bool&`/`const bool&` parameter is not stripped down to `BoolType` and
the rule fires even though no actual type conversion happens (only a
reference binding to the same type).
This is confirmed against eclipse-score/communication, where nearly all
(46 of 51) open RULE-7-0-1 alerts are of this shape:
- `bool&`/`const bool&` out-parameters and variadic/generic logging
helpers (e.g. `LogInfo(logger, some_bool_expr, ...)`).
- `std::pair`-style forwarding-reference constructors instantiated with
`bool` (e.g. `return {value, overflow_flag};`,
`map::insert()`-returned pairs consumed via structured bindings),
reported as "Conversion from 'bool' to 'type &'" because the
parameter's *un-instantiated* template type is shown.
Add the missing exclusion: also strip a top-level reference before the
`BoolType` check. Verified locally against a real CodeQL database built
from `//score/message_passing` and `//score/mw/com` in
eclipse-score/communication: RULE-7-0-1 findings drop from 49 to 5, and
the 5 remaining are all genuine bool-to-numeric conversions
(`static_cast<uint8_t>(bool)`, etc.) that are unaffected by this change.
Extend the regression test with compliant cases for `bool&`,
`const bool&`, a forwarding-reference template parameter deduced as
`bool`, and `std::pair<T, bool>` construction.1 parent 4d0376a commit c45b003
4 files changed
Lines changed: 80 additions & 32 deletions
File tree
- change_notes
- cpp/misra
- src/rules/RULE-7-0-1
- test/rules/RULE-7-0-1
Lines changed: 9 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
26 | 35 | | |
27 | 36 | | |
28 | 37 | | |
| |||
Lines changed: 32 additions & 32 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
20 | 19 | | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
| |||
122 | 123 | | |
123 | 124 | | |
124 | 125 | | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
125 | 155 | | |
0 commit comments