From 802e6cdd78d0399947b15eac1d8c43c68a199d6f Mon Sep 17 00:00:00 2001 From: "rakesh.pothengil" Date: Wed, 23 Aug 2023 14:36:24 +0900 Subject: [PATCH 1/4] Fix for A5-1-3 false positives --- change_notes/2023-07-11-lambda-expr-without-param-list.md | 1 + .../src/rules/A5-1-3/LambdaExpressionWithoutParameterList.ql | 4 ++++ 2 files changed, 5 insertions(+) create mode 100644 change_notes/2023-07-11-lambda-expr-without-param-list.md diff --git a/change_notes/2023-07-11-lambda-expr-without-param-list.md b/change_notes/2023-07-11-lambda-expr-without-param-list.md new file mode 100644 index 0000000000..4a5b4cf5ad --- /dev/null +++ b/change_notes/2023-07-11-lambda-expr-without-param-list.md @@ -0,0 +1 @@ + - Only consider lambdas that have zero arguments, since any lambda with non-zero arguments will have an explicit argument list. diff --git a/cpp/autosar/src/rules/A5-1-3/LambdaExpressionWithoutParameterList.ql b/cpp/autosar/src/rules/A5-1-3/LambdaExpressionWithoutParameterList.ql index 4583f8675e..db39a62d8e 100644 --- a/cpp/autosar/src/rules/A5-1-3/LambdaExpressionWithoutParameterList.ql +++ b/cpp/autosar/src/rules/A5-1-3/LambdaExpressionWithoutParameterList.ql @@ -21,6 +21,10 @@ where not isExcluded(lambda, LambdasPackage::lambdaExpressionWithoutParameterListQuery()) and lambdaFunction = lambda.getLambdaFunction() and not lambdaFunction.isAffectedByMacro() and + // If it has a parameter, then it will have an + // explicit parameter list. Therefore, proceed to check only if the lambda + // does not have any parameters. + not exists (lambdaFunction.getAParameter()) and // The extractor doesn't store the syntactic information whether the parameter list // is enclosed in parenthesis. Therefore we cannot determine if the parameter list is // explicitly specified when the parameter list is empty. From 65b70abb8a29b0501a88559b31aab08b399b1045 Mon Sep 17 00:00:00 2001 From: Rakesh Pothengil <122329100+rak3-sh@users.noreply.github.com> Date: Wed, 30 Aug 2023 11:28:32 +0900 Subject: [PATCH 2/4] Update change_notes/2023-07-11-lambda-expr-without-param-list.md As per review comment. Co-authored-by: Luke Cartey <5377966+lcartey@users.noreply.github.com> --- change_notes/2023-07-11-lambda-expr-without-param-list.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/change_notes/2023-07-11-lambda-expr-without-param-list.md b/change_notes/2023-07-11-lambda-expr-without-param-list.md index 4a5b4cf5ad..d5f50e6853 100644 --- a/change_notes/2023-07-11-lambda-expr-without-param-list.md +++ b/change_notes/2023-07-11-lambda-expr-without-param-list.md @@ -1 +1 @@ - - Only consider lambdas that have zero arguments, since any lambda with non-zero arguments will have an explicit argument list. + - `A5-1-3` - Only consider lambdas that have zero arguments, since any lambda with non-zero arguments will have an explicit argument list. From a7dd290a650f9997c97763680bbbb8fa3574e0db Mon Sep 17 00:00:00 2001 From: "rakesh.pothengil" Date: Wed, 30 Aug 2023 11:36:51 +0900 Subject: [PATCH 3/4] Updated test --- cpp/autosar/test/rules/A5-1-3/test.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cpp/autosar/test/rules/A5-1-3/test.cpp b/cpp/autosar/test/rules/A5-1-3/test.cpp index cca6898710..50a041e925 100644 --- a/cpp/autosar/test/rules/A5-1-3/test.cpp +++ b/cpp/autosar/test/rules/A5-1-3/test.cpp @@ -28,4 +28,12 @@ void test() { l1 += 1; }; // clang-format on -} \ No newline at end of file +} + +#define PARAM_MACRO [](int i) { i; }; + +int test_lambda_in_macro() +{ + PARAM_MACRO // COMPLIANT + return 0; +} From 4297f0a82e461f2076f3db0834d8e79eadb7b8b3 Mon Sep 17 00:00:00 2001 From: "rakesh.pothengil" Date: Wed, 30 Aug 2023 19:26:31 +0900 Subject: [PATCH 4/4] Formatted using clang-format --- cpp/autosar/test/rules/A5-1-3/test.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cpp/autosar/test/rules/A5-1-3/test.cpp b/cpp/autosar/test/rules/A5-1-3/test.cpp index 50a041e925..d44419ff9b 100644 --- a/cpp/autosar/test/rules/A5-1-3/test.cpp +++ b/cpp/autosar/test/rules/A5-1-3/test.cpp @@ -32,8 +32,7 @@ void test() { #define PARAM_MACRO [](int i) { i; }; -int test_lambda_in_macro() -{ +int test_lambda_in_macro() { PARAM_MACRO // COMPLIANT - return 0; + return 0; }