Skip to content

Commit d65bfab

Browse files
jketemaCopilot
andcommitted
Test unused static variable with side-effecting initializer
Add a minimal initializer that increments a global and record the current unused-static-variable alert as spurious. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 835afbb commit d65bfab

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
| test.cpp:8:12:8:21 | staticVar6 | Static variable staticVar6 is never read. |
33
| test.cpp:10:11:10:19 | constVar8 | Static variable constVar8 is never read. |
44
| test.cpp:12:12:12:22 | staticVar10 | Static variable staticVar10 is never read. |
5+
| test.cpp:38:12:38:22 | initialized | Static variable initialized is never read. |

‎cpp/ql/test/query-tests/Best Practices/Unused Entities/UnusedStaticVariables/test.cpp‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,10 @@ class MyTemplateClass // never instantiated
2929
// ...
3030
}
3131
};
32+
33+
int initialize()
34+
{
35+
return ++globalVar;
36+
}
37+
38+
static int initialized = initialize(); // $ SPURIOUS: Alert // GOOD (initializer has a side effect)

0 commit comments

Comments
 (0)