From a00c620b091f55331c284d01ef2863dcfb019b0c Mon Sep 17 00:00:00 2001 From: Kristen Newbury Date: Tue, 30 Jan 2024 10:44:39 -0500 Subject: [PATCH 1/9] A13-3-1: exclude functions with different number parameters --- change_notes/2024-01-30-exclusion-a13-3-1.md | 2 ++ ...tContainsForwardingReferenceAsItsArgumentOverloaded.ql | 4 +++- ...insForwardingReferenceAsItsArgumentOverloaded.expected | 2 ++ cpp/autosar/test/rules/A13-3-1/test.cpp | 8 +++++++- 4 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 change_notes/2024-01-30-exclusion-a13-3-1.md diff --git a/change_notes/2024-01-30-exclusion-a13-3-1.md b/change_notes/2024-01-30-exclusion-a13-3-1.md new file mode 100644 index 0000000000..6e2571c463 --- /dev/null +++ b/change_notes/2024-01-30-exclusion-a13-3-1.md @@ -0,0 +1,2 @@ +`A13-3-1`: `cpp/autosar/function-that-contains-forwarding-reference-as-its-argument-overloaded` + - Fixes #399. Exclude functions that have different number of parameters. \ No newline at end of file diff --git a/cpp/autosar/src/rules/A13-3-1/FunctionThatContainsForwardingReferenceAsItsArgumentOverloaded.ql b/cpp/autosar/src/rules/A13-3-1/FunctionThatContainsForwardingReferenceAsItsArgumentOverloaded.ql index 7562082656..03c216829d 100644 --- a/cpp/autosar/src/rules/A13-3-1/FunctionThatContainsForwardingReferenceAsItsArgumentOverloaded.ql +++ b/cpp/autosar/src/rules/A13-3-1/FunctionThatContainsForwardingReferenceAsItsArgumentOverloaded.ql @@ -26,5 +26,7 @@ where not isExcluded(f, OperatorsPackage::functionThatContainsForwardingReferenceAsItsArgumentOverloadedQuery()) and not f.isDeleted() and - f = c.getAnOverload() + f = c.getAnOverload() and + //allow for overloading with different number of parameters + f.getNumberOfParameters() = c.getNumberOfParameters() select f, "Function overloads a $@ with a forwarding reference parameter.", c, "function" diff --git a/cpp/autosar/test/rules/A13-3-1/FunctionThatContainsForwardingReferenceAsItsArgumentOverloaded.expected b/cpp/autosar/test/rules/A13-3-1/FunctionThatContainsForwardingReferenceAsItsArgumentOverloaded.expected index 590f891ead..f90b1456a3 100644 --- a/cpp/autosar/test/rules/A13-3-1/FunctionThatContainsForwardingReferenceAsItsArgumentOverloaded.expected +++ b/cpp/autosar/test/rules/A13-3-1/FunctionThatContainsForwardingReferenceAsItsArgumentOverloaded.expected @@ -3,3 +3,5 @@ | test.cpp:50:3:50:3 | A | Function overloads a $@ with a forwarding reference parameter. | test.cpp:47:3:47:3 | A | function | | test.cpp:63:8:63:8 | B | Function overloads a $@ with a forwarding reference parameter. | test.cpp:66:3:66:3 | B | function | | test.cpp:63:8:63:8 | B | Function overloads a $@ with a forwarding reference parameter. | test.cpp:66:3:66:3 | B | function | +| test.cpp:71:7:71:7 | C | Function overloads a $@ with a forwarding reference parameter. | test.cpp:74:25:74:25 | C | function | +| test.cpp:71:7:71:7 | C | Function overloads a $@ with a forwarding reference parameter. | test.cpp:74:25:74:25 | C | function | diff --git a/cpp/autosar/test/rules/A13-3-1/test.cpp b/cpp/autosar/test/rules/A13-3-1/test.cpp index 4a706b53e2..9cd33ad4e9 100644 --- a/cpp/autosar/test/rules/A13-3-1/test.cpp +++ b/cpp/autosar/test/rules/A13-3-1/test.cpp @@ -66,4 +66,10 @@ struct B { B(T &&value) {} }; -int main() {} \ No newline at end of file +int main() {} + +class C { +public: + C() {} // COMPLIANT by exception + template C(T &&) {} +}; \ No newline at end of file From 8706c3d1b7e7cd319ce87d84e653e0b605a82aca Mon Sep 17 00:00:00 2001 From: Kristen Newbury Date: Mon, 5 Feb 2024 09:47:43 -0500 Subject: [PATCH 2/9] A13-3-1: address formatting review --- change_notes/2024-01-30-exclusion-a13-3-1.md | 2 +- ...onThatContainsForwardingReferenceAsItsArgumentOverloaded.ql | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/change_notes/2024-01-30-exclusion-a13-3-1.md b/change_notes/2024-01-30-exclusion-a13-3-1.md index 6e2571c463..f5307a7720 100644 --- a/change_notes/2024-01-30-exclusion-a13-3-1.md +++ b/change_notes/2024-01-30-exclusion-a13-3-1.md @@ -1,2 +1,2 @@ -`A13-3-1`: `cpp/autosar/function-that-contains-forwarding-reference-as-its-argument-overloaded` +`A13-3-1`: `FunctionThatContainsForwardingReferenceAsItsArgumentOverloaded.ql` - Fixes #399. Exclude functions that have different number of parameters. \ No newline at end of file diff --git a/cpp/autosar/src/rules/A13-3-1/FunctionThatContainsForwardingReferenceAsItsArgumentOverloaded.ql b/cpp/autosar/src/rules/A13-3-1/FunctionThatContainsForwardingReferenceAsItsArgumentOverloaded.ql index 03c216829d..5f22306768 100644 --- a/cpp/autosar/src/rules/A13-3-1/FunctionThatContainsForwardingReferenceAsItsArgumentOverloaded.ql +++ b/cpp/autosar/src/rules/A13-3-1/FunctionThatContainsForwardingReferenceAsItsArgumentOverloaded.ql @@ -27,6 +27,7 @@ where OperatorsPackage::functionThatContainsForwardingReferenceAsItsArgumentOverloadedQuery()) and not f.isDeleted() and f = c.getAnOverload() and - //allow for overloading with different number of parameters + // allow for overloading with different number of parameters, because there is no + // confusion on what function will be called. f.getNumberOfParameters() = c.getNumberOfParameters() select f, "Function overloads a $@ with a forwarding reference parameter.", c, "function" From b100f210c286c890fe83bae1c65fbea228f259db Mon Sep 17 00:00:00 2001 From: Kristen Newbury Date: Tue, 6 Feb 2024 11:54:38 -0500 Subject: [PATCH 3/9] A13-3-1: improve alert msg --- ...wardingReferenceAsItsArgumentOverloaded.ql | 19 ++++++++++++++++--- cpp/autosar/test/rules/A13-3-1/test.cpp | 8 +++++--- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/cpp/autosar/src/rules/A13-3-1/FunctionThatContainsForwardingReferenceAsItsArgumentOverloaded.ql b/cpp/autosar/src/rules/A13-3-1/FunctionThatContainsForwardingReferenceAsItsArgumentOverloaded.ql index 5f22306768..2f056257fb 100644 --- a/cpp/autosar/src/rules/A13-3-1/FunctionThatContainsForwardingReferenceAsItsArgumentOverloaded.ql +++ b/cpp/autosar/src/rules/A13-3-1/FunctionThatContainsForwardingReferenceAsItsArgumentOverloaded.ql @@ -21,7 +21,7 @@ class Candidate extends TemplateFunction { } } -from Candidate c, Function f +from Candidate c, Function f, Function overload, Function overloaded, string msg where not isExcluded(f, OperatorsPackage::functionThatContainsForwardingReferenceAsItsArgumentOverloadedQuery()) and @@ -29,5 +29,18 @@ where f = c.getAnOverload() and // allow for overloading with different number of parameters, because there is no // confusion on what function will be called. - f.getNumberOfParameters() = c.getNumberOfParameters() -select f, "Function overloads a $@ with a forwarding reference parameter.", c, "function" + f.getNumberOfParameters() = c.getNumberOfParameters() and + //build a dynamic select statement that guarantees to read that the overloading function is the explicit one + if + (f instanceof CopyConstructor or f instanceof MoveConstructor) and + f.isCompilerGenerated() + then ( + msg = "implicit constructor" and + overloaded = f and + overload = c + ) else ( + msg = "function" and + overloaded = c and + overload = f + ) +select overload, "Function overloads a $@ with a forwarding reference parameter.", overloaded, msg diff --git a/cpp/autosar/test/rules/A13-3-1/test.cpp b/cpp/autosar/test/rules/A13-3-1/test.cpp index 9cd33ad4e9..ab75917a66 100644 --- a/cpp/autosar/test/rules/A13-3-1/test.cpp +++ b/cpp/autosar/test/rules/A13-3-1/test.cpp @@ -61,9 +61,11 @@ A b(a); void F1(int &) = delete; // COMPLIANT by exception struct B { - template ::value> * = nullptr> - B(T &&value) {} + template < + typename T, + std::enable_if_t>, A>::value> * = nullptr> + B(T &&value) {} // COMPLIANT by exception }; int main() {} From 117c942110fece6480e5c66d682cae82bd1c5c91 Mon Sep 17 00:00:00 2001 From: Kristen Newbury Date: Wed, 7 Feb 2024 10:17:58 -0500 Subject: [PATCH 4/9] Update change_notes/2024-01-30-exclusion-a13-3-1.md Co-authored-by: Remco Vermeulen --- change_notes/2024-01-30-exclusion-a13-3-1.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/change_notes/2024-01-30-exclusion-a13-3-1.md b/change_notes/2024-01-30-exclusion-a13-3-1.md index f5307a7720..7033fb040e 100644 --- a/change_notes/2024-01-30-exclusion-a13-3-1.md +++ b/change_notes/2024-01-30-exclusion-a13-3-1.md @@ -1,2 +1,2 @@ -`A13-3-1`: `FunctionThatContainsForwardingReferenceAsItsArgumentOverloaded.ql` +`A13-3-1` - `FunctionThatContainsForwardingReferenceAsItsArgumentOverloaded.ql`: - Fixes #399. Exclude functions that have different number of parameters. \ No newline at end of file From defd27e752efa025bc7b9c41e0b6570671419ec6 Mon Sep 17 00:00:00 2001 From: Kristen Newbury Date: Wed, 7 Feb 2024 10:54:59 -0500 Subject: [PATCH 5/9] A13-3-1: improve alert message --- ...nsForwardingReferenceAsItsArgumentOverloaded.ql | 10 +++++++--- ...ardingReferenceAsItsArgumentOverloaded.expected | 14 +++++++------- cpp/autosar/test/rules/A13-3-1/test.cpp | 5 +++-- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/cpp/autosar/src/rules/A13-3-1/FunctionThatContainsForwardingReferenceAsItsArgumentOverloaded.ql b/cpp/autosar/src/rules/A13-3-1/FunctionThatContainsForwardingReferenceAsItsArgumentOverloaded.ql index 2f056257fb..aeaf0f12b6 100644 --- a/cpp/autosar/src/rules/A13-3-1/FunctionThatContainsForwardingReferenceAsItsArgumentOverloaded.ql +++ b/cpp/autosar/src/rules/A13-3-1/FunctionThatContainsForwardingReferenceAsItsArgumentOverloaded.ql @@ -21,7 +21,9 @@ class Candidate extends TemplateFunction { } } -from Candidate c, Function f, Function overload, Function overloaded, string msg +from + Candidate c, Function f, Function overload, Function overloaded, string msg, + string firstMsgSegment where not isExcluded(f, OperatorsPackage::functionThatContainsForwardingReferenceAsItsArgumentOverloadedQuery()) and @@ -36,11 +38,13 @@ where f.isCompilerGenerated() then ( msg = "implicit constructor" and + firstMsgSegment = " with a forwarding reference parameter " and overloaded = f and overload = c ) else ( - msg = "function" and + msg = "function with a forwarding reference parameter" and + firstMsgSegment = " " and overloaded = c and overload = f ) -select overload, "Function overloads a $@ with a forwarding reference parameter.", overloaded, msg +select overload, "Function" + firstMsgSegment + "overloads a $@.", overloaded, msg diff --git a/cpp/autosar/test/rules/A13-3-1/FunctionThatContainsForwardingReferenceAsItsArgumentOverloaded.expected b/cpp/autosar/test/rules/A13-3-1/FunctionThatContainsForwardingReferenceAsItsArgumentOverloaded.expected index f90b1456a3..545719520d 100644 --- a/cpp/autosar/test/rules/A13-3-1/FunctionThatContainsForwardingReferenceAsItsArgumentOverloaded.expected +++ b/cpp/autosar/test/rules/A13-3-1/FunctionThatContainsForwardingReferenceAsItsArgumentOverloaded.expected @@ -1,7 +1,7 @@ -| test.cpp:24:6:24:7 | F1 | Function overloads a $@ with a forwarding reference parameter. | test.cpp:27:25:27:26 | F1 | function | -| test.cpp:49:3:49:3 | A | Function overloads a $@ with a forwarding reference parameter. | test.cpp:47:3:47:3 | A | function | -| test.cpp:50:3:50:3 | A | Function overloads a $@ with a forwarding reference parameter. | test.cpp:47:3:47:3 | A | function | -| test.cpp:63:8:63:8 | B | Function overloads a $@ with a forwarding reference parameter. | test.cpp:66:3:66:3 | B | function | -| test.cpp:63:8:63:8 | B | Function overloads a $@ with a forwarding reference parameter. | test.cpp:66:3:66:3 | B | function | -| test.cpp:71:7:71:7 | C | Function overloads a $@ with a forwarding reference parameter. | test.cpp:74:25:74:25 | C | function | -| test.cpp:71:7:71:7 | C | Function overloads a $@ with a forwarding reference parameter. | test.cpp:74:25:74:25 | C | function | +| test.cpp:24:6:24:7 | F1 | Function overloads a $@. | test.cpp:27:25:27:26 | F1 | function with a forwarding reference parameter | +| test.cpp:50:3:50:3 | A | Function overloads a $@. | test.cpp:48:3:48:3 | A | function with a forwarding reference parameter | +| test.cpp:51:3:51:3 | A | Function overloads a $@. | test.cpp:48:3:48:3 | A | function with a forwarding reference parameter | +| test.cpp:69:3:69:3 | B | Function with a forwarding reference parameter overloads a $@. | test.cpp:64:8:64:8 | B | implicit constructor | +| test.cpp:69:3:69:3 | B | Function with a forwarding reference parameter overloads a $@. | test.cpp:64:8:64:8 | B | implicit constructor | +| test.cpp:77:25:77:25 | C | Function with a forwarding reference parameter overloads a $@. | test.cpp:74:7:74:7 | C | implicit constructor | +| test.cpp:77:25:77:25 | C | Function with a forwarding reference parameter overloads a $@. | test.cpp:74:7:74:7 | C | implicit constructor | diff --git a/cpp/autosar/test/rules/A13-3-1/test.cpp b/cpp/autosar/test/rules/A13-3-1/test.cpp index ab75917a66..8b63ea2bda 100644 --- a/cpp/autosar/test/rules/A13-3-1/test.cpp +++ b/cpp/autosar/test/rules/A13-3-1/test.cpp @@ -39,7 +39,8 @@ template void F1(T &&x) {} // class A { public: - // COMPLIANT by exception, constrained to not match copy/move ctors + // COMPLIANT[FALSE_POSITIVE] - by exception, constrained to not match + // copy/move ctors template < typename T, std::enable_if_t>, A>::value> * = nullptr> - B(T &&value) {} // COMPLIANT by exception + B(T &&value) {} // COMPLIANT[FALSE_POSITIVE] - by exception }; int main() {} From ec5fb2ace60749965cd3f77aeab221feaad6e3f7 Mon Sep 17 00:00:00 2001 From: Kristen Newbury Date: Wed, 7 Feb 2024 19:33:51 -0500 Subject: [PATCH 6/9] Update cpp/autosar/test/rules/A13-3-1/test.cpp Co-authored-by: Remco Vermeulen --- cpp/autosar/test/rules/A13-3-1/test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cpp/autosar/test/rules/A13-3-1/test.cpp b/cpp/autosar/test/rules/A13-3-1/test.cpp index 8b63ea2bda..f2f8022edc 100644 --- a/cpp/autosar/test/rules/A13-3-1/test.cpp +++ b/cpp/autosar/test/rules/A13-3-1/test.cpp @@ -73,6 +73,6 @@ int main() {} class C { public: - C() {} // COMPLIANT by exception - template C(T &&) {} + C() {} + template C(T &&) {} // COMPLIANT by exception }; \ No newline at end of file From add36bcf8da57aaaa2875720711c16dae3bc781d Mon Sep 17 00:00:00 2001 From: Kristen Newbury Date: Wed, 7 Feb 2024 21:07:54 -0500 Subject: [PATCH 7/9] A13-3-1: improve alert message --- ...tContainsForwardingReferenceAsItsArgumentOverloaded.ql | 8 +++++++- ...insForwardingReferenceAsItsArgumentOverloaded.expected | 8 ++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/cpp/autosar/src/rules/A13-3-1/FunctionThatContainsForwardingReferenceAsItsArgumentOverloaded.ql b/cpp/autosar/src/rules/A13-3-1/FunctionThatContainsForwardingReferenceAsItsArgumentOverloaded.ql index aeaf0f12b6..393c1222fd 100644 --- a/cpp/autosar/src/rules/A13-3-1/FunctionThatContainsForwardingReferenceAsItsArgumentOverloaded.ql +++ b/cpp/autosar/src/rules/A13-3-1/FunctionThatContainsForwardingReferenceAsItsArgumentOverloaded.ql @@ -37,7 +37,13 @@ where (f instanceof CopyConstructor or f instanceof MoveConstructor) and f.isCompilerGenerated() then ( - msg = "implicit constructor" and + ( + f instanceof CopyConstructor and + msg = "implicit copy constructor" + or + f instanceof MoveConstructor and + msg = "implicit move constructor" + ) and firstMsgSegment = " with a forwarding reference parameter " and overloaded = f and overload = c diff --git a/cpp/autosar/test/rules/A13-3-1/FunctionThatContainsForwardingReferenceAsItsArgumentOverloaded.expected b/cpp/autosar/test/rules/A13-3-1/FunctionThatContainsForwardingReferenceAsItsArgumentOverloaded.expected index 545719520d..6e79cb00a4 100644 --- a/cpp/autosar/test/rules/A13-3-1/FunctionThatContainsForwardingReferenceAsItsArgumentOverloaded.expected +++ b/cpp/autosar/test/rules/A13-3-1/FunctionThatContainsForwardingReferenceAsItsArgumentOverloaded.expected @@ -1,7 +1,7 @@ | test.cpp:24:6:24:7 | F1 | Function overloads a $@. | test.cpp:27:25:27:26 | F1 | function with a forwarding reference parameter | | test.cpp:50:3:50:3 | A | Function overloads a $@. | test.cpp:48:3:48:3 | A | function with a forwarding reference parameter | | test.cpp:51:3:51:3 | A | Function overloads a $@. | test.cpp:48:3:48:3 | A | function with a forwarding reference parameter | -| test.cpp:69:3:69:3 | B | Function with a forwarding reference parameter overloads a $@. | test.cpp:64:8:64:8 | B | implicit constructor | -| test.cpp:69:3:69:3 | B | Function with a forwarding reference parameter overloads a $@. | test.cpp:64:8:64:8 | B | implicit constructor | -| test.cpp:77:25:77:25 | C | Function with a forwarding reference parameter overloads a $@. | test.cpp:74:7:74:7 | C | implicit constructor | -| test.cpp:77:25:77:25 | C | Function with a forwarding reference parameter overloads a $@. | test.cpp:74:7:74:7 | C | implicit constructor | +| test.cpp:69:3:69:3 | B | Function with a forwarding reference parameter overloads a $@. | test.cpp:64:8:64:8 | B | implicit copy constructor | +| test.cpp:69:3:69:3 | B | Function with a forwarding reference parameter overloads a $@. | test.cpp:64:8:64:8 | B | implicit move constructor | +| test.cpp:77:25:77:25 | C | Function with a forwarding reference parameter overloads a $@. | test.cpp:74:7:74:7 | C | implicit copy constructor | +| test.cpp:77:25:77:25 | C | Function with a forwarding reference parameter overloads a $@. | test.cpp:74:7:74:7 | C | implicit move constructor | From 0eb430a6610efd4bff4d8f8e3eda3b5037577cdb Mon Sep 17 00:00:00 2001 From: Kristen Newbury Date: Wed, 7 Feb 2024 21:11:28 -0500 Subject: [PATCH 8/9] A13-3-1: reformat test --- cpp/autosar/test/rules/A13-3-1/test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/autosar/test/rules/A13-3-1/test.cpp b/cpp/autosar/test/rules/A13-3-1/test.cpp index f2f8022edc..163f1fffc3 100644 --- a/cpp/autosar/test/rules/A13-3-1/test.cpp +++ b/cpp/autosar/test/rules/A13-3-1/test.cpp @@ -73,6 +73,6 @@ int main() {} class C { public: - C() {} + C() {} template C(T &&) {} // COMPLIANT by exception }; \ No newline at end of file From ed29794724bb9d03120ba325d8fec6f703aae667 Mon Sep 17 00:00:00 2001 From: Kristen Newbury Date: Thu, 8 Feb 2024 13:58:24 -0500 Subject: [PATCH 9/9] A13-3-1: fix mislabelled testcase --- cpp/autosar/test/rules/A13-3-1/test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/autosar/test/rules/A13-3-1/test.cpp b/cpp/autosar/test/rules/A13-3-1/test.cpp index 163f1fffc3..82fe866a0a 100644 --- a/cpp/autosar/test/rules/A13-3-1/test.cpp +++ b/cpp/autosar/test/rules/A13-3-1/test.cpp @@ -74,5 +74,5 @@ int main() {} class C { public: C() {} - template C(T &&) {} // COMPLIANT by exception + template C(T &&) {} // NON_COMPLIANT }; \ No newline at end of file