File tree Expand file tree Collapse file tree 5 files changed +38
-0
lines changed
src/Best Practices/Unused Entities
test/query-tests/Best Practices/Unused Entities/UnusedStaticVariables Expand file tree Collapse file tree 5 files changed +38
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Improvements to C/C++ analysis
2
+
3
+ ## General improvements
4
+
5
+ ## New queries
6
+
7
+ | ** Query** | ** Tags** | ** Purpose** |
8
+ | -----------------------------| -----------| --------------------------------------------------------------------|
9
+
10
+ ## Changes to existing queries
11
+
12
+ | ** Query** | ** Expected impact** | ** Change** |
13
+ | ----------------------------| ------------------------| ------------------------------------------------------------------|
14
+ | Unused static variable (` cpp/unused-static-variable ` ) | Fewer false positive results | Variables with the attribute ` unused ` are now excluded from the query. |
15
+
16
+ ## Changes to QL libraries
Original file line number Diff line number Diff line change @@ -25,4 +25,5 @@ where v.isStatic()
25
25
and not v instanceof MemberVariable
26
26
and not declarationHasSideEffects ( v )
27
27
and not v .getAnAttribute ( ) .hasName ( "used" )
28
+ and not v .getAnAttribute ( ) .hasName ( "unused" )
28
29
select v , "Static variable " + v .getName ( ) + " is never read"
Original file line number Diff line number Diff line change
1
+ | test.cpp:7:12:7:21 | staticVar5 | Static variable staticVar5 is never read |
2
+ | test.cpp:8:12:8:21 | staticVar6 | Static variable staticVar6 is never read |
Original file line number Diff line number Diff line change
1
+ Best Practices/Unused Entities/UnusedStaticVariables.ql
Original file line number Diff line number Diff line change
1
+
2
+ int globalVar; // GOOD (not static)
3
+ static int staticVar1; // GOOD (used)
4
+ static int staticVar2; // GOOD (used)
5
+ static int staticVar3 = 3 ; // GOOD (used)
6
+ static int staticVar4 = staticVar3; // GOOD (used)
7
+ static int staticVar5; // BAD (unused)
8
+ static int staticVar6 = 6 ; // BAD (unused)
9
+ static __attribute__ ((__unused__)) int staticVar7; // GOOD (unused but this is expected)
10
+
11
+ void f ()
12
+ {
13
+ int *ptr = &staticVar4;
14
+
15
+ staticVar1 = staticVar2;
16
+ (*ptr) = 0 ;
17
+ }
18
+
You can’t perform that action at this time.
0 commit comments