Skip to content

Commit c1d45c3

Browse files
committed
A5-1-9: Exclude duplication through macros
1 parent a568b88 commit c1d45c3

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

cpp/autosar/src/rules/A5-1-9/IdenticalLambdaExpressions.ql

+9-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ where
2424
not lambdaExpression = otherLambdaExpression and
2525
not lambdaExpression.isFromTemplateInstantiation(_) and
2626
not otherLambdaExpression.isFromTemplateInstantiation(_) and
27-
getLambdaHashCons(lambdaExpression) = getLambdaHashCons(otherLambdaExpression)
27+
getLambdaHashCons(lambdaExpression) = getLambdaHashCons(otherLambdaExpression) and
28+
// Do not report lambdas produced by the same macro in different invocations
29+
not exists(Macro m, MacroInvocation m1, MacroInvocation m2 |
30+
m1 = m.getAnInvocation() and
31+
m2 = m.getAnInvocation() and
32+
not m1 = m2 and // Lambdas in the same macro can be reported
33+
m1.getAnExpandedElement() = lambdaExpression and
34+
m2.getAnExpandedElement() = otherLambdaExpression
35+
)
2836
select lambdaExpression, "Lambda expression is identical to $@ lambda expression.",
2937
otherLambdaExpression, "this"

cpp/autosar/test/rules/A5-1-9/test.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,10 @@ class Test_issue468 {
104104
LogError("Error");
105105
LogFatal("Fatal");
106106
}
107-
};
107+
};
108+
109+
#define MACRO() [](int i) -> int { return i + 3; }
110+
void test_macros() {
111+
MACRO(); // COMPLIANT
112+
MACRO(); // COMPLIANT - no duplication
113+
}

0 commit comments

Comments
 (0)