From 868ba258e98256fffcb7173ffd7e8daa762a2218 Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Thu, 1 Oct 2026 09:56:39 +0100 Subject: [PATCH 1/5] C++: Establish that PointlessComparison.ql and PointlessSelfComparison.ql don't overlap (at least in the main case). --- .../Arithmetic/PointlessComparison/PointlessComparison.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cpp/ql/test/query-tests/Likely Bugs/Arithmetic/PointlessComparison/PointlessComparison.cpp b/cpp/ql/test/query-tests/Likely Bugs/Arithmetic/PointlessComparison/PointlessComparison.cpp index d6462ea2b991..461a1a2131ce 100644 --- a/cpp/ql/test/query-tests/Likely Bugs/Arithmetic/PointlessComparison/PointlessComparison.cpp +++ b/cpp/ql/test/query-tests/Likely Bugs/Arithmetic/PointlessComparison/PointlessComparison.cpp @@ -43,3 +43,9 @@ int extreme_values(void) if (y >> 1 >= 0x7FFFFFFFFFFF) {} // $ Alert[cpp/constant-comparison] // always true if (y >> 1 >= 0xFFFFFFFFFFF) {} // $ Alert[cpp/constant-comparison] // always true } + +// Test for overlap between PointlessComparison and PointlessSelfComparison +// (PointlessComparison should *not* report this) +bool selfCmp1(int x) { + return (x == (int)x); +} From 59b74581a290182eff20f36a2a7370f1b73b9f01 Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Thu, 1 Oct 2026 10:57:31 +0100 Subject: [PATCH 2/5] C++: Add a test for cpp/empty-if (AI). --- .../FutileConditional/FutileConditional.cpp | 15 +++++++++++++++ .../FutileConditional/FutileConditional.expected | 2 ++ .../FutileConditional/FutileConditional.qlref | 2 ++ 3 files changed, 19 insertions(+) create mode 100644 cpp/ql/test/query-tests/Likely Bugs/Likely Typos/FutileConditional/FutileConditional.cpp create mode 100644 cpp/ql/test/query-tests/Likely Bugs/Likely Typos/FutileConditional/FutileConditional.expected create mode 100644 cpp/ql/test/query-tests/Likely Bugs/Likely Typos/FutileConditional/FutileConditional.qlref diff --git a/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/FutileConditional/FutileConditional.cpp b/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/FutileConditional/FutileConditional.cpp new file mode 100644 index 000000000000..00c9c969c469 --- /dev/null +++ b/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/FutileConditional/FutileConditional.cpp @@ -0,0 +1,15 @@ +void emptyIfs(int value) { + if (value) {} // $ Alert + + if (value > 1) { + } // $ Alert + + if (value) { + ++value; + } + + if (value) { + } else { + ++value; + } +} diff --git a/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/FutileConditional/FutileConditional.expected b/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/FutileConditional/FutileConditional.expected new file mode 100644 index 000000000000..136258f326a2 --- /dev/null +++ b/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/FutileConditional/FutileConditional.expected @@ -0,0 +1,2 @@ +| FutileConditional.cpp:2:3:2:15 | if (...) ... | If-statement with an empty then-branch and no else-branch. | +| FutileConditional.cpp:4:3:5:3 | if (...) ... | If-statement with an empty then-branch and no else-branch. | diff --git a/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/FutileConditional/FutileConditional.qlref b/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/FutileConditional/FutileConditional.qlref new file mode 100644 index 000000000000..a64e5b47b5bf --- /dev/null +++ b/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/FutileConditional/FutileConditional.qlref @@ -0,0 +1,2 @@ +query: Likely Bugs/Likely Typos/FutileConditional.ql +postprocess: utils/test/InlineExpectationsTestQuery.ql From 344f808554a1021371afd7d2a66b4efdf033e88d Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Thu, 1 Oct 2026 11:03:42 +0100 Subject: [PATCH 3/5] C++: Adjust and expand the test. --- .../FutileConditional/FutileConditional.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/FutileConditional/FutileConditional.cpp b/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/FutileConditional/FutileConditional.cpp index 00c9c969c469..3cc9567932bd 100644 --- a/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/FutileConditional/FutileConditional.cpp +++ b/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/FutileConditional/FutileConditional.cpp @@ -1,15 +1,19 @@ void emptyIfs(int value) { - if (value) {} // $ Alert + if (value) {} // $ Alert[cpp/empty-if] if (value > 1) { - } // $ Alert + } // $ Alert[cpp/empty-if] - if (value) { + if (value) { // good ++value; } - if (value) { + if (value) { // good } else { ++value; } + + if (value) { // $ MISSING: Alert[cpp/empty-if] + } else { + } } From 4561fb86e2e70eb47491dfc5104b7f90e8a63de6 Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Thu, 1 Oct 2026 11:48:49 +0100 Subject: [PATCH 4/5] C++: Add some test cases from cpp/empty-if to the test for cpp/empty-block (exploring overlap). --- .../EmptyBlock/EmptyBlock.expected | 4 ++++ .../Likely Errors/EmptyBlock/empty_block.cpp | 20 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/cpp/ql/test/query-tests/Best Practices/Likely Errors/EmptyBlock/EmptyBlock.expected b/cpp/ql/test/query-tests/Best Practices/Likely Errors/EmptyBlock/EmptyBlock.expected index dc572fae9bef..d6d9c209c79a 100644 --- a/cpp/ql/test/query-tests/Best Practices/Likely Errors/EmptyBlock/EmptyBlock.expected +++ b/cpp/ql/test/query-tests/Best Practices/Likely Errors/EmptyBlock/EmptyBlock.expected @@ -1,3 +1,7 @@ | empty_block.cpp:9:10:9:11 | { ... } | Empty block without comment. | | empty_block.cpp:12:10:13:3 | { ... } | Empty block without comment. | | empty_block.cpp:20:10:21:3 | { ... } | Empty block without comment. | +| empty_block.cpp:84:14:85:3 | { ... } | Empty block without comment. | +| empty_block.cpp:93:10:94:3 | { ... } | Empty block without comment. | +| empty_block.cpp:99:10:100:3 | { ... } | Empty block without comment. | +| empty_block.cpp:100:10:101:3 | { ... } | Empty block without comment. | diff --git a/cpp/ql/test/query-tests/Best Practices/Likely Errors/EmptyBlock/empty_block.cpp b/cpp/ql/test/query-tests/Best Practices/Likely Errors/EmptyBlock/empty_block.cpp index 8a8714d310f4..905b873c670d 100644 --- a/cpp/ql/test/query-tests/Best Practices/Likely Errors/EmptyBlock/empty_block.cpp +++ b/cpp/ql/test/query-tests/Best Practices/Likely Errors/EmptyBlock/empty_block.cpp @@ -80,5 +80,25 @@ int f(int x) { } } + // BAD + if (x > 1) { + } + + // GOOD + if (x) { + ++x; + } + + // DUBIOUS (reported) + if (x) { + } else { + ++x; + } + + // BAD (x2) + if (x) { + } else { + } + return 1; } From bef877a8dee1e7888779a5e480b8ee6f4181f484 Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Fri, 2 Oct 2026 15:52:11 +0100 Subject: [PATCH 5/5] C++: Consistent capitalization. --- .../Likely Typos/FutileConditional/FutileConditional.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/FutileConditional/FutileConditional.cpp b/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/FutileConditional/FutileConditional.cpp index 3cc9567932bd..1635300ac9a9 100644 --- a/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/FutileConditional/FutileConditional.cpp +++ b/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/FutileConditional/FutileConditional.cpp @@ -4,11 +4,11 @@ void emptyIfs(int value) { if (value > 1) { } // $ Alert[cpp/empty-if] - if (value) { // good + if (value) { // GOOD ++value; } - if (value) { // good + if (value) { // GOOD } else { ++value; }