Skip to content

Commit a4a0314

Browse files
committed
Move definition to Operator.qll
1 parent 3e1e18e commit a4a0314

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

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

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,8 @@
1313

1414
import cpp
1515
import codingstandards.cpp.autosar
16+
import codingstandards.cpp.Operator
1617

17-
from Operator o
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-
)
18+
from UnaryAddressOfOperator o
19+
where not isExcluded(o, OperatorsPackage::unaryOperatorOverloadedQuery())
2620
select o, "The unary & operator overloaded."

cpp/common/src/codingstandards/cpp/Operator.qll

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,3 +264,19 @@ class UserOverloadedOperator extends Function {
264264
not this.isCompilerGenerated()
265265
}
266266
}
267+
268+
/** A user defined operator address of operator (`&`). */
269+
class UnaryAddressOfOperator extends Operator {
270+
UnaryAddressOfOperator() {
271+
hasName("operator&") and
272+
(
273+
// If this is a member function, it needs to have zero arguments to be the unary addressof
274+
// operator
275+
if this instanceof MemberFunction
276+
then getNumberOfParameters() = 0
277+
else
278+
// Otherwise it needs one argument to be unary
279+
getNumberOfParameters() = 1
280+
)
281+
}
282+
}

0 commit comments

Comments
 (0)