Skip to content

Commit 3e1e18e

Browse files
committed
M5-3-3: Excude binary operators.
Rule only applies to the unary operator&.
1 parent d9f0911 commit 3e1e18e

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* `M5-3-3` - exclude binary user defined `operator&` from this rule.

cpp/autosar/src/rules/M5-3-3/UnaryOperatorOverloaded.ql

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,12 @@ import cpp
1515
import codingstandards.cpp.autosar
1616

1717
from Operator o
18-
where not isExcluded(o, OperatorsPackage::unaryOperatorOverloadedQuery()) and o.hasName("operator&")
18+
where
19+
not isExcluded(o, OperatorsPackage::unaryOperatorOverloadedQuery()) and
20+
o.hasName("operator&") and
21+
(
22+
if o instanceof MemberFunction
23+
then o.getNumberOfParameters() = 0
24+
else o.getNumberOfParameters() = 1
25+
)
1926
select o, "The unary & operator overloaded."
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
| test.cpp:6:5:6:13 | operator& | The unary & operator overloaded. |
1+
| test.cpp:2:5:2:13 | operator& | The unary & operator overloaded. |
2+
| test.cpp:8:3:8:11 | operator& | The unary & operator overloaded. |
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
/* The unary & operator shall not be overloaded */
2-
// do not defined it at all
3-
class A
4-
5-
{
6-
A operator&(); // NON_COMPLIANT
1+
class A {
2+
A operator&(); // NON_COMPLIANT - unary
3+
constexpr A operator&(const A rhs); // COMPLIANT - binary
74
};
5+
6+
class B {};
7+
8+
B operator&(B b); // NON_COMPLIANT - unary
9+
constexpr B operator&(const B lhs, const B rhs); // COMPLIANT - binary

0 commit comments

Comments
 (0)