Commit 8bcf85d
committed
Fix RULE-5-10-1 false positives on compiler-predefined function identifiers
RULE-5-10-1 (poorly-formed identifier) flagged the compiler-predefined
function identifiers __func__, __FUNCTION__ and __PRETTY_FUNCTION__ for
containing double underscores / leading underscores. These are not
user-defined identifiers: __func__ is mandated by the C++ standard and
__FUNCTION__/__PRETTY_FUNCTION__ are GCC/Clang extensions, synthesized
once per enclosing function. They frequently surface via assert-style
macros, producing one finding per macro invocation site (on this
codebase, 228 findings, ~79% of the rule's results).
The shared IdentifierIntroduction library already excludes
`variable.isCompilerGenerated()`, but the extractor does not mark these
predefined variables as compiler generated, so they leak through.
Exclude them in VariableDeclarationEntryIdentifier using a
name-independent structural signal: they are `static` local variables
with no definition (their only declaration entry is located at a use
site), whereas a genuine `static` local always has an in-source
definition. This deliberately avoids hard-coding the names, so a user
who really declares such an identifier (on a compiler that does not
predefine it) still has a definition and is therefore still flagged.
Add a regression test to RULE-5-10-1 covering __func__ and
__PRETTY_FUNCTION__ (COMPLIANT). The false positive reproduces in the
single-translation-unit test harness: without this fix the test fails
with the four spurious findings; with it the test passes. The existing
RULE-5-10-1 and Identifiers library tests continue to pass.
Fixes #11701 parent 62bf905 commit 8bcf85d
4 files changed
Lines changed: 33 additions & 1 deletion
File tree
- change_notes
- cpp
- common/src/codingstandards/cpp
- misra/test/rules/RULE-5-10-1
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
332 | 332 | | |
333 | 333 | | |
334 | 334 | | |
335 | | - | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
336 | 349 | | |
337 | 350 | | |
338 | 351 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| 52 | + | |
| 53 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
186 | 186 | | |
187 | 187 | | |
188 | 188 | | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
189 | 204 | | |
190 | 205 | | |
191 | 206 | | |
| |||
0 commit comments