Skip to content

Commit af0d0f5

Browse files
committed
update
1 parent 2e51f7c commit af0d0f5

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

cpp/autosar/src/rules/A13-5-2/UserDefinedConversionOperatorsNotDefinedExplicit.ql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import cpp
1616
import codingstandards.cpp.autosar
1717

18+
// import semmle.code.cpp.PrintAST
1819
class ExplicitConversionOperator extends ConversionOperator {
1920
ExplicitConversionOperator() {
2021
exists(Specifier spec |
@@ -27,5 +28,7 @@ class ExplicitConversionOperator extends ConversionOperator {
2728
from ConversionOperator op
2829
where
2930
not isExcluded(op, OperatorsPackage::userDefinedConversionOperatorsNotDefinedExplicitQuery()) and
30-
not op instanceof ExplicitConversionOperator
31+
not op instanceof ExplicitConversionOperator and
32+
not op.isCompilerGenerated()
3133
select op, "User-defined conversion operator is not explicit."
34+
// select 1

cpp/autosar/test/rules/A13-5-2/test.cpp

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,36 @@ class A {
88
operator int() const { return d; } // NON_COMPLIANT
99
private:
1010
float d;
11-
};
11+
};
12+
13+
void example() {
14+
15+
int ref_value{0};
16+
int other_value{0};
17+
18+
// ok
19+
auto dummy_lambda = [&ref_value]() noexcept -> void { ref_value = 42; };
20+
dummy_lambda();
21+
22+
// ok
23+
auto my_lambda_1 = [&ref_value](int param) noexcept -> void {
24+
for (int i{0}; i < param; ++i) {
25+
++ref_value;
26+
}
27+
};
28+
my_lambda_1(other_value);
29+
30+
// error: user-defined-conversion-operators-not-defined-explicit
31+
auto my_lambda_2 = [](int param) noexcept -> void {
32+
for (int i{0}; i < param; ++i) {
33+
//
34+
}
35+
};
36+
my_lambda_2(other_value);
37+
38+
// ok
39+
auto my_lambda_3 = [&ref_value](int param) noexcept -> void {
40+
ref_value = param;
41+
};
42+
my_lambda_3(other_value);
43+
}

0 commit comments

Comments
 (0)