forked from github/codeql-coding-standards
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCopyAndMoveNotDeclaredProtected.ql
More file actions
64 lines (60 loc) · 2.28 KB
/
CopyAndMoveNotDeclaredProtected.ql
File metadata and controls
64 lines (60 loc) · 2.28 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* @id cpp/autosar/copy-and-move-not-declared-protected
* @name A12-8-6: Copy and move constructors and copy assignment and move assignment operators shall be declared
* @description Copy and move constructors and copy assignment and move assignment operators shall
* be declared protected or defined '=delete' in base class.
* @kind problem
* @precision very-high
* @problem.severity error
* @tags external/autosar/id/a12-8-6
* external/autosar/allocated-target/implementation
* external/autosar/enforcement/automated
* external/autosar/obligation/required
*/
import cpp
import codingstandards.cpp.autosar
import codingstandards.cpp.Class
predicate isInvalidConstructor(Constructor f, string constructorType) {
not f.isDeleted() and
not f.isProtected() and
(
f instanceof MoveConstructor and
if f.isCompilerGenerated()
then constructorType = "Implicit move constructor"
else constructorType = "Move constructor"
or
f instanceof CopyConstructor and
if f.isCompilerGenerated()
then constructorType = "Implicit copy constructor"
else constructorType = "Copy constructor"
)
}
predicate isInvalidAssignment(Operator f, string operatorType) {
not f.isDeleted() and
(
f instanceof MoveAssignmentOperator and
if f.isCompilerGenerated()
then operatorType = "Implicit move assignment operator"
else operatorType = "Move constructor"
or
f instanceof CopyAssignmentOperator and
if f.isCompilerGenerated()
then operatorType = "Implicit copy assignment operator"
else operatorType = "Copy assignment operator"
) and
not f.hasSpecifier("protected")
}
from BaseClass baseClass, MemberFunction mf, string type
where
not isExcluded(mf, OperatorsPackage::copyAndMoveNotDeclaredProtectedQuery()) and
(
isInvalidConstructor(mf, type)
or
isInvalidAssignment(mf, type)
) and
baseClass = mf.getDeclaringType()
// To avoid duplicate alerts due to inaccurate location information in the database we don't use the location of the base class.
// This for example happens if multiple copies of the same header file are present in the database.
select getDeclarationEntryInClassDeclaration(mf),
type + " for base class '" + baseClass.getQualifiedName() +
"' is not declared protected or deleted."