File tree Expand file tree Collapse file tree 2 files changed +37
-2
lines changed Expand file tree Collapse file tree 2 files changed +37
-2
lines changed Original file line number Diff line number Diff line change 15
15
import cpp
16
16
import codingstandards.cpp.autosar
17
17
18
+ // import semmle.code.cpp.PrintAST
18
19
class ExplicitConversionOperator extends ConversionOperator {
19
20
ExplicitConversionOperator ( ) {
20
21
exists ( Specifier spec |
@@ -27,5 +28,7 @@ class ExplicitConversionOperator extends ConversionOperator {
27
28
from ConversionOperator op
28
29
where
29
30
not isExcluded ( op , OperatorsPackage:: userDefinedConversionOperatorsNotDefinedExplicitQuery ( ) ) and
30
- not op instanceof ExplicitConversionOperator
31
+ not op instanceof ExplicitConversionOperator and
32
+ not op .isCompilerGenerated ( )
31
33
select op , "User-defined conversion operator is not explicit."
34
+ // select 1
Original file line number Diff line number Diff line change @@ -8,4 +8,36 @@ class A {
8
8
operator int () const { return d; } // NON_COMPLIANT
9
9
private:
10
10
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
+ }
You can’t perform that action at this time.
0 commit comments