Repository navigation
Description
Observed problem
With CodeQL CLI 2.27.6, codeql-action 4.39.5, C++ build-mode: none, the quality query cpp/unused-static-variable reports a constant that is passed to three function-template calls. The Google Test dependency needed by the included test helpers is fetched by CMake and is absent during buildless extraction.
Fresh failing run: https://github.com/linksplatform/Collections.Methods/actions/runs/47387913134 (commit 2cf78cf79018d4a84028efbe5a93857f02a7d15d). The quality gate logs cpp/Platform.Collections.Methods.Tests.Console/App.cpp:63 cpp/unused-static-variable. This run deliberately removed our previous query exclusion to recheck the current release. I searched this tracker for unused-static-variable + buildless/template and found no existing exact report.
Reproduction
Use the source at the above commit and run:
- uses: github/codeql-action/init@915412ff23e8b7659517e607487dbeae018f2934
with:
languages: c-cpp
build-mode: none
queries: security-extended,security-and-quality
- uses: github/codeql-action/analyze@915412ff23e8b7659517e607487dbeae018f2934The relevant source is small in concept:
int main() {
static const int _n = 2000;
// Each actual call supplies tree/allocation/free/root/count arguments:
TestExtensions::TestMultipleCreationsAndDeletions(tree, allocate, free, root, count, _n);
}This excerpt illustrates the dependency boundary; the linked repository revision is the tested reproducer, including the declarations and three actual calls. Full source: https://github.com/linksplatform/Collections.Methods/blob/2cf78cf79018d4a84028efbe5a93857f02a7d15d/cpp/Platform.Collections.Methods.Tests.Console/App.cpp#L63 . The includes lead into fetched Google Test headers. The variable is visibly used at lines 69, 76 and 83; an unused-variable alert should not be emitted even if the call target cannot be fully resolved.
Local handling and proposed fix
We are removing the broad cpp/unused-static-variable exclusion in PR linksplatform/Collections.Methods#122 and declaring this compile-time count as constexpr int _n = 2000, which does not need static storage. No test or benchmark is removed. Analysis of the updated declaration is being checked separately in that PR.
Suggested extractor/query fix: preserve syntactic variable references in arguments of unresolved/dependent calls, or avoid a definitive unused-variable diagnostic for those references until extraction can establish usage. An extraction regression around a local static integral constant passed into a function-template call across a missing third-party-header boundary would prevent recurrence. We would appreciate guidance on reducing this tested repository reproducer to the smallest extractor fixture.
Activity