C++: exclude uninitialized uses that are cast to void

This eliminates FPs caused by casting a variable explicitly to
void type. Developers use this cast to suppress compiler warnings
on unused variables, e.g.
   (void) x;
This commit is contained in:
Mingjie Shen
2023-07-03 02:12:00 -04:00
parent 95ddc01ccb
commit 9218afedbe
2 changed files with 11 additions and 0 deletions

View File

@@ -72,6 +72,13 @@ VariableAccess commonException() {
or
result.getParent() instanceof BuiltInOperation
or
// Ignore the uninitialized use that is explicitly cast to void and
// is also an expression statement.
(
result.getActualType() instanceof VoidType and
result.getParent() instanceof ExprStmt
)
or
// Finally, exclude functions that contain assembly blocks. It's
// anyone's guess what happens in those.
containsInlineAssembly(result.getEnclosingFunction())

View File

@@ -0,0 +1,4 @@
---
category: minorAnalysis
---
* The `cpp/uninitialized-local` query now excludes uninitialized uses that are explicitly cast to void and are expression statements. As a result, the query will report less false positives.