From 5125835faf703ce45fa0bdcef06cfc40db37df51 Mon Sep 17 00:00:00 2001 From: Paolo Tranquilli Date: Thu, 2 Apr 2026 12:24:24 +0200 Subject: [PATCH] C++: Port to new just-based language test definition Add justfiles for C++ following the pattern of other ported languages (go, rust, swift). Move consistency queries from semmle-code's semmlecode-cpp-consistency-queries/ to ql/cpp/ql/consistency-queries/. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- cpp/justfile | 7 +++++++ cpp/ql/consistency-queries/badLocations.ql | 9 +++++++++ cpp/ql/consistency-queries/nullInToString.ql | 5 +++++ cpp/ql/consistency-queries/qlpack.yml | 5 +++++ cpp/ql/consistency-queries/unusedLocations.ql | 10 ++++++++++ .../variableDeclarationsWithoutTypes.ql | 5 +++++ cpp/ql/consistency-queries/variablesWithoutTypes.ql | 5 +++++ cpp/ql/justfile | 6 ++++++ cpp/ql/test/justfile | 11 +++++++++++ 9 files changed, 63 insertions(+) create mode 100644 cpp/justfile create mode 100644 cpp/ql/consistency-queries/badLocations.ql create mode 100644 cpp/ql/consistency-queries/nullInToString.ql create mode 100644 cpp/ql/consistency-queries/qlpack.yml create mode 100644 cpp/ql/consistency-queries/unusedLocations.ql create mode 100644 cpp/ql/consistency-queries/variableDeclarationsWithoutTypes.ql create mode 100644 cpp/ql/consistency-queries/variablesWithoutTypes.ql create mode 100644 cpp/ql/justfile create mode 100644 cpp/ql/test/justfile diff --git a/cpp/justfile b/cpp/justfile new file mode 100644 index 00000000000..52cbbd7b892 --- /dev/null +++ b/cpp/justfile @@ -0,0 +1,7 @@ +import '../lib.just' + +[group('build')] +build: (_build_dist "cpp") + +[group('test')] +language-tests *EXTRA_ARGS: (_language_tests EXTRA_ARGS source_dir() 'ql/test' '../../semmlecode-cpp-tests') diff --git a/cpp/ql/consistency-queries/badLocations.ql b/cpp/ql/consistency-queries/badLocations.ql new file mode 100644 index 00000000000..385d3d92fe6 --- /dev/null +++ b/cpp/ql/consistency-queries/badLocations.ql @@ -0,0 +1,9 @@ +import cpp + +// Locations should either be :0:0:0:0 locations (UnknownLocation, or +// a whole file), or all 4 fields should be positive. +from Location l +where + [l.getStartLine(), l.getEndLine(), l.getStartColumn(), l.getEndColumn()] != 0 and + [l.getStartLine(), l.getEndLine(), l.getStartColumn(), l.getEndColumn()] < 1 +select l diff --git a/cpp/ql/consistency-queries/nullInToString.ql b/cpp/ql/consistency-queries/nullInToString.ql new file mode 100644 index 00000000000..4a6385b519a --- /dev/null +++ b/cpp/ql/consistency-queries/nullInToString.ql @@ -0,0 +1,5 @@ +import cpp + +from Element e +where e.toString().matches("%(null)%") +select e diff --git a/cpp/ql/consistency-queries/qlpack.yml b/cpp/ql/consistency-queries/qlpack.yml new file mode 100644 index 00000000000..fed0e22e17b --- /dev/null +++ b/cpp/ql/consistency-queries/qlpack.yml @@ -0,0 +1,5 @@ +name: codeql/cpp-consistency-queries +groups: [cpp, test, consistency-queries] +dependencies: + codeql/cpp-all: ${workspace} +extractor: cpp diff --git a/cpp/ql/consistency-queries/unusedLocations.ql b/cpp/ql/consistency-queries/unusedLocations.ql new file mode 100644 index 00000000000..875c60ba325 --- /dev/null +++ b/cpp/ql/consistency-queries/unusedLocations.ql @@ -0,0 +1,10 @@ +import cpp + +from Location l +where + not any(Element e).getLocation() = l and + not any(LambdaCapture lc).getLocation() = l and + not any(MacroAccess ma).getActualLocation() = l and + not any(NamespaceDeclarationEntry nde).getBodyLocation() = l and + not any(XmlLocatable xml).getLocation() = l +select l diff --git a/cpp/ql/consistency-queries/variableDeclarationsWithoutTypes.ql b/cpp/ql/consistency-queries/variableDeclarationsWithoutTypes.ql new file mode 100644 index 00000000000..2573d660def --- /dev/null +++ b/cpp/ql/consistency-queries/variableDeclarationsWithoutTypes.ql @@ -0,0 +1,5 @@ +import cpp + +from VariableDeclarationEntry i +where not exists(i.getType()) +select i diff --git a/cpp/ql/consistency-queries/variablesWithoutTypes.ql b/cpp/ql/consistency-queries/variablesWithoutTypes.ql new file mode 100644 index 00000000000..d004c175abd --- /dev/null +++ b/cpp/ql/consistency-queries/variablesWithoutTypes.ql @@ -0,0 +1,5 @@ +import cpp + +from Variable i +where not exists(i.getType()) +select i diff --git a/cpp/ql/justfile b/cpp/ql/justfile new file mode 100644 index 00000000000..ff0e4c1090f --- /dev/null +++ b/cpp/ql/justfile @@ -0,0 +1,6 @@ +import "../../lib.just" + +[no-cd] +format *ARGS=".": (_format_ql ARGS) + +consistency_queries := source_dir() / "consistency-queries" diff --git a/cpp/ql/test/justfile b/cpp/ql/test/justfile new file mode 100644 index 00000000000..a3d05a28814 --- /dev/null +++ b/cpp/ql/test/justfile @@ -0,0 +1,11 @@ +import "../justfile" + +base_flags := "--include-location-in-star" + +all_checks := default_db_checks + """\ + --check-undefined-labels \ + --check-unused-labels \ + --consistency-queries=""" + consistency_queries + +[no-cd] +test *ARGS=".": (_codeql_test "cpp" base_flags all_checks ARGS)