diff --git a/cpp/ql/src/Best Practices/Unused Entities/UnusedLocals.ql b/cpp/ql/src/Best Practices/Unused Entities/UnusedLocals.ql index 6d5948300db1..0239d19899f0 100644 --- a/cpp/ql/src/Best Practices/Unused Entities/UnusedLocals.ql +++ b/cpp/ql/src/Best Practices/Unused Entities/UnusedLocals.ql @@ -54,6 +54,7 @@ from LocalVariable v, Function f where f = v.getFunction() and not exists(v.getAnAccess()) and + not v.isCompilerGenerated() and not v.isConst() and // workaround for folded constants not exists(DeclStmt ds | ds.getADeclaration() = v and ds.isInMacroExpansion()) and // variable declared in a macro expansion not declarationHasSideEffects(v) and diff --git a/cpp/ql/src/change-notes/2026-11-26-unused-local-variable-compiler-generated.md b/cpp/ql/src/change-notes/2026-11-26-unused-local-variable-compiler-generated.md new file mode 100644 index 000000000000..36936f5a6f0e --- /dev/null +++ b/cpp/ql/src/change-notes/2026-11-26-unused-local-variable-compiler-generated.md @@ -0,0 +1,4 @@ +--- +category: minorAnalysis +--- +* The `cpp/unused-local-variable` query no longer reports compiler-generated variables, such as placeholders for empty function parameter packs. diff --git a/cpp/ql/test/query-tests/Best Practices/Unused Entities/UnusedLocals/code2.cpp b/cpp/ql/test/query-tests/Best Practices/Unused Entities/UnusedLocals/code2.cpp index e033a69f9610..01d65105caf1 100644 --- a/cpp/ql/test/query-tests/Best Practices/Unused Entities/UnusedLocals/code2.cpp +++ b/cpp/ql/test/query-tests/Best Practices/Unused Entities/UnusedLocals/code2.cpp @@ -193,3 +193,18 @@ void test_initializer_side_effect() { int initialized = initialize(); // GOOD (initializer has a side effect) } + +// --- + +void use(...); + +template +void f_args(const Args&... args) // GOOD: the compiler-generated parameter pack should be ignored +{ + use(args...); +} + +void test_call_f_args() +{ + f_args(); +}