From af0d0f506fb7a38c871347b1c9f36a1d681dab45 Mon Sep 17 00:00:00 2001 From: Jeongsoo Lee Date: Mon, 6 Feb 2023 16:18:21 -0800 Subject: [PATCH 1/6] update --- ...edConversionOperatorsNotDefinedExplicit.ql | 5 ++- cpp/autosar/test/rules/A13-5-2/test.cpp | 34 ++++++++++++++++++- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/cpp/autosar/src/rules/A13-5-2/UserDefinedConversionOperatorsNotDefinedExplicit.ql b/cpp/autosar/src/rules/A13-5-2/UserDefinedConversionOperatorsNotDefinedExplicit.ql index 5e83d02baa..9eb7b2d38b 100644 --- a/cpp/autosar/src/rules/A13-5-2/UserDefinedConversionOperatorsNotDefinedExplicit.ql +++ b/cpp/autosar/src/rules/A13-5-2/UserDefinedConversionOperatorsNotDefinedExplicit.ql @@ -15,6 +15,7 @@ import cpp import codingstandards.cpp.autosar +// import semmle.code.cpp.PrintAST class ExplicitConversionOperator extends ConversionOperator { ExplicitConversionOperator() { exists(Specifier spec | @@ -27,5 +28,7 @@ class ExplicitConversionOperator extends ConversionOperator { from ConversionOperator op where not isExcluded(op, OperatorsPackage::userDefinedConversionOperatorsNotDefinedExplicitQuery()) and - not op instanceof ExplicitConversionOperator + not op instanceof ExplicitConversionOperator and + not op.isCompilerGenerated() select op, "User-defined conversion operator is not explicit." +// select 1 diff --git a/cpp/autosar/test/rules/A13-5-2/test.cpp b/cpp/autosar/test/rules/A13-5-2/test.cpp index 0f9f7a3b3d..48684cb3e6 100644 --- a/cpp/autosar/test/rules/A13-5-2/test.cpp +++ b/cpp/autosar/test/rules/A13-5-2/test.cpp @@ -8,4 +8,36 @@ class A { operator int() const { return d; } // NON_COMPLIANT private: float d; -}; \ No newline at end of file +}; + +void example() { + + int ref_value{0}; + int other_value{0}; + + // ok + auto dummy_lambda = [&ref_value]() noexcept -> void { ref_value = 42; }; + dummy_lambda(); + + // ok + auto my_lambda_1 = [&ref_value](int param) noexcept -> void { + for (int i{0}; i < param; ++i) { + ++ref_value; + } + }; + my_lambda_1(other_value); + + // error: user-defined-conversion-operators-not-defined-explicit + auto my_lambda_2 = [](int param) noexcept -> void { + for (int i{0}; i < param; ++i) { + // + } + }; + my_lambda_2(other_value); + + // ok + auto my_lambda_3 = [&ref_value](int param) noexcept -> void { + ref_value = param; + }; + my_lambda_3(other_value); +} From 5a103979b126e57348e6dc269b2edcdc099b9770 Mon Sep 17 00:00:00 2001 From: Jeongsoo Lee Date: Tue, 7 Feb 2023 13:56:42 -0800 Subject: [PATCH 2/6] update test.cpp --- cpp/autosar/test/rules/A13-5-2/test.cpp | 33 ++++++------------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/cpp/autosar/test/rules/A13-5-2/test.cpp b/cpp/autosar/test/rules/A13-5-2/test.cpp index 48684cb3e6..c8cc4a41cd 100644 --- a/cpp/autosar/test/rules/A13-5-2/test.cpp +++ b/cpp/autosar/test/rules/A13-5-2/test.cpp @@ -10,34 +10,15 @@ class A { float d; }; -void example() { +void test_compiler_generated() { + int x = 0; - int ref_value{0}; - int other_value{0}; - - // ok - auto dummy_lambda = [&ref_value]() noexcept -> void { ref_value = 42; }; - dummy_lambda(); - - // ok - auto my_lambda_1 = [&ref_value](int param) noexcept -> void { - for (int i{0}; i < param; ++i) { - ++ref_value; - } - }; - my_lambda_1(other_value); - - // error: user-defined-conversion-operators-not-defined-explicit - auto my_lambda_2 = [](int param) noexcept -> void { - for (int i{0}; i < param; ++i) { - // - } + auto capture = [x]() -> int { + return x; }; - my_lambda_2(other_value); - // ok - auto my_lambda_3 = [&ref_value](int param) noexcept -> void { - ref_value = param; + auto no_capture = []() -> int { + int x = 1; + return x; }; - my_lambda_3(other_value); } From 0ad2ab362f411290dd6b5752801b027aa28263a8 Mon Sep 17 00:00:00 2001 From: Jeongsoo Lee Date: Tue, 7 Feb 2023 14:33:10 -0800 Subject: [PATCH 3/6] format test.cpp --- cpp/autosar/test/rules/A13-5-2/test.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/cpp/autosar/test/rules/A13-5-2/test.cpp b/cpp/autosar/test/rules/A13-5-2/test.cpp index c8cc4a41cd..37bc0d0fdb 100644 --- a/cpp/autosar/test/rules/A13-5-2/test.cpp +++ b/cpp/autosar/test/rules/A13-5-2/test.cpp @@ -13,9 +13,7 @@ class A { void test_compiler_generated() { int x = 0; - auto capture = [x]() -> int { - return x; - }; + auto capture = [x]() -> int { return x; }; auto no_capture = []() -> int { int x = 1; From 2fb5f48cfafd887b87df28224393caed664a4234 Mon Sep 17 00:00:00 2001 From: Jeongsoo Lee Date: Thu, 23 Feb 2023 15:49:18 -0800 Subject: [PATCH 4/6] Clean up commented code --- .../A13-5-2/UserDefinedConversionOperatorsNotDefinedExplicit.ql | 2 -- 1 file changed, 2 deletions(-) diff --git a/cpp/autosar/src/rules/A13-5-2/UserDefinedConversionOperatorsNotDefinedExplicit.ql b/cpp/autosar/src/rules/A13-5-2/UserDefinedConversionOperatorsNotDefinedExplicit.ql index 9eb7b2d38b..ced94c5bdd 100644 --- a/cpp/autosar/src/rules/A13-5-2/UserDefinedConversionOperatorsNotDefinedExplicit.ql +++ b/cpp/autosar/src/rules/A13-5-2/UserDefinedConversionOperatorsNotDefinedExplicit.ql @@ -15,7 +15,6 @@ import cpp import codingstandards.cpp.autosar -// import semmle.code.cpp.PrintAST class ExplicitConversionOperator extends ConversionOperator { ExplicitConversionOperator() { exists(Specifier spec | @@ -31,4 +30,3 @@ where not op instanceof ExplicitConversionOperator and not op.isCompilerGenerated() select op, "User-defined conversion operator is not explicit." -// select 1 From e9749e400420d5991b7139cc96ae6acb146882b3 Mon Sep 17 00:00:00 2001 From: Jeongsoo Lee Date: Thu, 23 Feb 2023 15:54:41 -0800 Subject: [PATCH 5/6] Add missing change note --- change_notes/2022-02-23-a13-5-2-fix-reported-fp-for-a13-5-2.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 change_notes/2022-02-23-a13-5-2-fix-reported-fp-for-a13-5-2.md diff --git a/change_notes/2022-02-23-a13-5-2-fix-reported-fp-for-a13-5-2.md b/change_notes/2022-02-23-a13-5-2-fix-reported-fp-for-a13-5-2.md new file mode 100644 index 0000000000..736d559ce3 --- /dev/null +++ b/change_notes/2022-02-23-a13-5-2-fix-reported-fp-for-a13-5-2.md @@ -0,0 +1 @@ +- Address a false positive on `a13-5-2` where lambda expressions with empty captures were being flagged as having a non-compliant conversion operator. \ No newline at end of file From 8f29669b57b0d2514ef53d28b7181dcb07afdc9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jeongsoo=20Lee=20=28=EC=9D=B4=EC=A0=95=EC=88=98=29?= Date: Tue, 7 Mar 2023 11:02:59 -0800 Subject: [PATCH 6/6] Update change_notes/2022-02-23-a13-5-2-fix-reported-fp-for-a13-5-2.md Co-authored-by: Luke Cartey <5377966+lcartey@users.noreply.github.com> --- change_notes/2022-02-23-a13-5-2-fix-reported-fp-for-a13-5-2.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/change_notes/2022-02-23-a13-5-2-fix-reported-fp-for-a13-5-2.md b/change_notes/2022-02-23-a13-5-2-fix-reported-fp-for-a13-5-2.md index 736d559ce3..5719e30b1d 100644 --- a/change_notes/2022-02-23-a13-5-2-fix-reported-fp-for-a13-5-2.md +++ b/change_notes/2022-02-23-a13-5-2-fix-reported-fp-for-a13-5-2.md @@ -1 +1 @@ -- Address a false positive on `a13-5-2` where lambda expressions with empty captures were being flagged as having a non-compliant conversion operator. \ No newline at end of file +- `A13-5-2` - address a false positive where lambda expressions with empty captures were being flagged as having a non-compliant conversion operator. \ No newline at end of file