-
Notifications
You must be signed in to change notification settings - Fork 76
Expand file tree
/
Copy pathImproperlyProvidedSpecialMemberFunctionsAudit.ql
More file actions
49 lines (45 loc) · 1.63 KB
/
ImproperlyProvidedSpecialMemberFunctionsAudit.ql
File metadata and controls
49 lines (45 loc) · 1.63 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/**
* @id cpp/misra/improperly-provided-special-member-functions-audit
* @name RULE-15-0-1: Special member functions shall be provided appropriately, Audit
* @description Audit: incorrect provision of special member functions can lead to unexpected or
* undefined behavior when objects of the class are copied, moved, or destroyed.
* @kind problem
* @precision low
* @problem.severity warning
* @tags external/misra/id/rule-15-0-1
* scope/single-translation-unit
* correctness
* external/misra/audit
* maintainability
* external/misra/enforcement/decidable
* external/misra/obligation/required
*/
import cpp
import codingstandards.cpp.misra
import AnalyzableClass
string missingKind(Class c) {
not c.getAConstructor() instanceof MoveConstructor and
result = "move constructor"
or
not c.getAMemberFunction() instanceof MoveAssignmentOperator and
result = "move assignment operator"
or
not c.getAConstructor() instanceof CopyConstructor and
result = "copy constructor"
or
not c.getAMemberFunction() instanceof CopyAssignmentOperator and
result = "copy assignment operator"
or
not c.getAMemberFunction() instanceof Destructor and
result = "destructor"
}
string missingKinds(Class c) { result = concat(missingKind(c), " and ") }
from Class c, string kinds
where
not isExcluded(c, Classes3Package::improperlyProvidedSpecialMemberFunctionsAuditQuery()) and
not c instanceof AnalyzableClass and
not c.isPod() and
kinds = missingKinds(c)
select c,
"Class '" + c.getName() + "' is not analyzable because the " + kinds +
" are not present in the CodeQL database."