-
Notifications
You must be signed in to change notification settings - Fork 76
Expand file tree
/
Copy pathNonConstPredicateFunctionObject.ql
More file actions
33 lines (31 loc) · 1.33 KB
/
NonConstPredicateFunctionObject.ql
File metadata and controls
33 lines (31 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/**
* @id cpp/misra/non-const-predicate-function-object
* @name RULE-28-3-1: Predicates shall not have persistent side effects
* @description Much of the behavior of predicates is implementation defined, such as how and when
* it is invoked with which argument values, and if it is copied or moved. Therefore,
* predicate function objects should be declared const.
* @kind problem
* @precision very-high
* @problem.severity error
* @tags external/misra/id/rule-28-3-1
* scope/system
* correctness
* maintainability
* portability
* external/misra/enforcement/undecidable
* external/misra/obligation/required
*/
import cpp
import codingstandards.cpp.misra
import codingstandards.cpp.SideEffect
import codingstandards.cpp.types.Predicate
from MemberFunction callOperator, PredicateFunctionObject obj, Locatable usageSite
where
not isExcluded([callOperator, usageSite],
SideEffects6Package::nonConstPredicateFunctionObjectQuery()) and
obj.getSubstitution().getASubstitutionSite() = usageSite and
callOperator = obj.getCallOperator() and
not callOperator instanceof ConstMemberFunction
select usageSite, "Predicate usage of $@ has $@", callOperator.getDeclaringType(),
"callable object " + callOperator.getDeclaringType().getName(), callOperator,
"non const operator()."