From 73c075d2bc1b745a00efa5b1a4cbc5e8ede13b74 Mon Sep 17 00:00:00 2001 From: "rakesh.pothengil" Date: Wed, 13 Nov 2024 14:36:39 +0900 Subject: [PATCH 1/2] Fix #796 --- change_notes/2024-11-13-fix-fp-796.md | 2 ++ ...onThatContainsForwardingReferenceAsItsArgumentOverloaded.ql | 3 +++ 2 files changed, 5 insertions(+) create mode 100644 change_notes/2024-11-13-fix-fp-796.md diff --git a/change_notes/2024-11-13-fix-fp-796.md b/change_notes/2024-11-13-fix-fp-796.md new file mode 100644 index 000000000..5fa32f57e --- /dev/null +++ b/change_notes/2024-11-13-fix-fp-796.md @@ -0,0 +1,2 @@ + - `A13-3-1` - `FunctionThatContainsForwardingReferenceAsItsArgumentOverloaded.ql`: + - Reduce false positives by explicitly checking that the locations of overloaded functions are different. diff --git a/cpp/autosar/src/rules/A13-3-1/FunctionThatContainsForwardingReferenceAsItsArgumentOverloaded.ql b/cpp/autosar/src/rules/A13-3-1/FunctionThatContainsForwardingReferenceAsItsArgumentOverloaded.ql index 81ca7039c..e3fb59bd8 100644 --- a/cpp/autosar/src/rules/A13-3-1/FunctionThatContainsForwardingReferenceAsItsArgumentOverloaded.ql +++ b/cpp/autosar/src/rules/A13-3-1/FunctionThatContainsForwardingReferenceAsItsArgumentOverloaded.ql @@ -29,6 +29,9 @@ where OperatorsPackage::functionThatContainsForwardingReferenceAsItsArgumentOverloadedQuery()) and not f.isDeleted() and f = c.getAnOverload() and + // CodeQL sometimes fetches an overloaded function at the same location. + // Thus, a check is added explicitly (refer #796). + f.getLocation() != c.getLocation() and // allow for overloading with different number of parameters, because there is no // confusion on what function will be called. f.getNumberOfParameters() = c.getNumberOfParameters() and From 56d886e8cd24d9ee2c9120e91881d9174f8a5b89 Mon Sep 17 00:00:00 2001 From: "rakesh.pothengil" Date: Tue, 26 Nov 2024 13:05:28 +0900 Subject: [PATCH 2/2] Fix as per review comments --- ...hatContainsForwardingReferenceAsItsArgumentOverloaded.ql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cpp/autosar/src/rules/A13-3-1/FunctionThatContainsForwardingReferenceAsItsArgumentOverloaded.ql b/cpp/autosar/src/rules/A13-3-1/FunctionThatContainsForwardingReferenceAsItsArgumentOverloaded.ql index e3fb59bd8..1ae2bc87a 100644 --- a/cpp/autosar/src/rules/A13-3-1/FunctionThatContainsForwardingReferenceAsItsArgumentOverloaded.ql +++ b/cpp/autosar/src/rules/A13-3-1/FunctionThatContainsForwardingReferenceAsItsArgumentOverloaded.ql @@ -14,6 +14,7 @@ import cpp import codingstandards.cpp.autosar +import codingstandards.cpp.FunctionEquivalence class Candidate extends TemplateFunction { Candidate() { @@ -29,9 +30,8 @@ where OperatorsPackage::functionThatContainsForwardingReferenceAsItsArgumentOverloadedQuery()) and not f.isDeleted() and f = c.getAnOverload() and - // CodeQL sometimes fetches an overloaded function at the same location. - // Thus, a check is added explicitly (refer #796). - f.getLocation() != c.getLocation() and + // Ensure the functions are not equivalent to each other (refer #796). + not f = getAnEquivalentFunction(c) and // allow for overloading with different number of parameters, because there is no // confusion on what function will be called. f.getNumberOfParameters() = c.getNumberOfParameters() and