Skip to content

Commit 79bda00

Browse files
committed
C++: Work around issue with 'Unknown literal'.
1 parent 35f4646 commit 79bda00

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

cpp/ql/src/Best Practices/Unused Entities/UnusedLocals.ql

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,9 @@ where
5757
not declarationHasSideEffects(v) and
5858
not exists(AsmStmt s | f = s.getEnclosingFunction()) and
5959
not v.getAnAttribute().getName() = "unused" and
60-
not any(ErrorExpr e).getEnclosingFunction() = f // unextracted expr likely used `v`
60+
not any(ErrorExpr e).getEnclosingFunction() = f and // unextracted expr may use `v`
61+
not exists(Literal l |
62+
l.getEnclosingFunction() = f and
63+
not exists(l.getValue())
64+
)
6165
select v, "Variable " + v.getName() + " is not used"

cpp/ql/test/query-tests/Best Practices/Unused Entities/UnusedLocals/UnusedLocals.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
| code2.cpp:108:11:108:12 | v2 | Variable v2 is not used |
99
| code2.cpp:128:9:128:9 | b | Variable b is not used |
1010
| code2.cpp:141:18:141:18 | b | Variable b is not used |
11-
| code2.cpp:162:14:162:16 | obj | Variable obj is not used |
1211
| code.c:10:18:10:18 | y | Variable y is not used |
1312
| code.c:11:18:11:18 | z | Variable z is not used |
1413
| code.c:18:7:18:7 | x | Variable x is not used |

0 commit comments

Comments
 (0)