Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- `RULE-15-1-3` - `NonExplicitConversionMember.ql`:
- Fixed false positives on the compiler-generated conversion operator of a
captureless lambda's closure type (conversion to a function pointer). This
operator is implicit by definition and cannot be declared `explicit`.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ where
exists(ConversionOperator co |
x = co and
not co.isExplicit() and
// The conversion to a function pointer of a captureless lambda is
// compiler-generated and cannot be declared explicit.
not co.getDeclaringType() instanceof Closure and
message = "Conversion operator shall be explicit."
)
)
Expand Down
14 changes: 13 additions & 1 deletion cpp/misra/test/rules/RULE-15-1-3/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,16 @@ class TestClass7 {
operator double() const; // NON_COMPLIANT
operator const char *() const; // NON_COMPLIANT
explicit operator void *() const; // COMPLIANT
};
};

void test_lambdas() {
// The conversion to a function pointer of a captureless lambda's closure
// type is compiler-generated and cannot be declared explicit.
auto l1 = [](std::int32_t a) { return a; }; // COMPLIANT
auto l2 = [](auto a) { return a; }; // COMPLIANT
l2(1);
std::int32_t captured = 0;
auto l3 = [captured](std::int32_t a) { return a + captured; }; // COMPLIANT
(void)l1;
(void)l3;
}
Loading