Skip to content

Commit 5c613c7

Browse files
committed
M5-14-1: refactor expr extension
1 parent 1daf1d5 commit 5c613c7

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

cpp/autosar/src/rules/M5-14-1/RightHandOperandOfALogicalAndOperatorsContainSideEffects.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ import cpp
1818
import codingstandards.cpp.autosar
1919
import codingstandards.cpp.SideEffect
2020
import codingstandards.cpp.sideeffect.DefaultEffects
21+
import codingstandards.cpp.Expr
2122

2223
from BinaryLogicalOperation op, Expr rhs
2324
where
2425
not isExcluded(op,
2526
SideEffects1Package::rightHandOperandOfALogicalAndOperatorsContainSideEffectsQuery()) and
2627
rhs = op.getRightOperand() and
2728
hasSideEffect(rhs) and
28-
not rhs.(NoExceptExpr).getExpr().isUnevaluated() and
29-
not rhs.(SizeofExprOperator).getExprOperand().isUnevaluated()
29+
not rhs instanceof UnevaluatedExprExtension
3030
select op, "The $@ may have a side effect that is not always evaluated.", rhs, "right-hand operand"

cpp/common/src/codingstandards/cpp/Expr.qll

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,3 +189,17 @@ module MisraExpr {
189189
CValue() { isCValue(this) }
190190
}
191191
}
192+
193+
/**
194+
* an operator that does not evaluate its operand
195+
*/
196+
class UnevaluatedExprExtension extends Expr {
197+
UnevaluatedExprExtension() {
198+
this.getChild(_).isUnevaluated()
199+
or
200+
exists(FunctionCall declval |
201+
declval.getTarget().hasQualifiedName("std", "declval") and
202+
declval.getAChild() = this
203+
)
204+
}
205+
}

0 commit comments

Comments
 (0)