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 1515import cpp
1616import codingstandards.cpp.autosar
1717
18+ // import semmle.code.cpp.PrintAST
1819class ExplicitConversionOperator extends ConversionOperator {
1920 ExplicitConversionOperator ( ) {
2021 exists ( Specifier spec |
@@ -27,5 +28,7 @@ class ExplicitConversionOperator extends ConversionOperator {
2728from ConversionOperator op
2829where
2930 not isExcluded ( op , OperatorsPackage:: userDefinedConversionOperatorsNotDefinedExplicitQuery ( ) ) and
30- not op instanceof ExplicitConversionOperator
31+ not op instanceof ExplicitConversionOperator and
32+ not op .isCompilerGenerated ( )
3133select 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 {
88 operator int () const { return d; } // NON_COMPLIANT
99private:
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+ }
You can’t perform that action at this time.
0 commit comments